27
28
// NewLocalGate create a new timer gate instance
30
>
lg := &LocalGateImpl{
31
>
timer: time.NewTimer(0),
32
>
nextWakeupTime: time.Time{},
33
>
fireCh: make(chan struct{}, 1),
34
>
closeCh: make(chan struct{}),
35
>
timeSource: timeSource,
36
>
}
37
>
// the timer should be stopped when initialized
38
>
if !lg.timer.Stop() {
39
// drain the existing signal if exist
40
<-lg.timer.C
41
}
42
44
>
defer close(lg.fireCh)
45
>
defer lg.timer.Stop()
46
>
loop:
47
>
for {
48
>
select {
49
case <-lg.timer.C:
50
select {