2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-25 07:12:17 +08:00

Update forwarder to use time.Timer

This commit is contained in:
Ken Hibino 2022-03-06 07:46:34 -08:00
parent ed69667e86
commit 088be63ee4

View File

@ -56,13 +56,15 @@ func (f *forwarder) start(wg *sync.WaitGroup) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
timer := time.NewTimer(f.avgInterval)
for { for {
select { select {
case <-f.done: case <-f.done:
f.logger.Debug("Forwarder done") f.logger.Debug("Forwarder done")
return return
case <-time.After(f.avgInterval): case <-timer.C:
f.exec() f.exec()
timer.Reset(f.avgInterval)
} }
} }
}() }()