2
0
mirror of https://github.com/hibiken/asynq.git synced 2026-06-29 10:15:24 +08:00

Use sync.WaitGroup for shutdown

This commit is contained in:
Ken Hibino
2020-02-15 23:14:30 -08:00
parent 2bcaea52ce
commit 3d9a222bb3
11 changed files with 51 additions and 18 deletions

View File

@@ -37,6 +37,9 @@ type Background struct {
// channel to send state updates.
stateCh chan<- string
// wait group to wait for all goroutines to finish.
wg sync.WaitGroup
rdb *rdb.RDB
scheduler *scheduler
processor *processor
@@ -211,11 +214,11 @@ func (bg *Background) start(handler Handler) {
bg.running = true
bg.processor.handler = handler
bg.heartbeater.start()
bg.subscriber.start()
bg.syncer.start()
bg.scheduler.start()
bg.processor.start()
bg.heartbeater.start(&bg.wg)
bg.subscriber.start(&bg.wg)
bg.syncer.start(&bg.wg)
bg.scheduler.start(&bg.wg)
bg.processor.start(&bg.wg)
}
// stops the background-task processing.
@@ -234,6 +237,8 @@ func (bg *Background) stop() {
bg.subscriber.terminate()
bg.heartbeater.terminate()
bg.wg.Wait()
bg.rdb.Close()
bg.processor.handler = nil
bg.running = false