From b3d6d26ccc3bb54fd7a8f9f8a2f7f9cd8b29348d Mon Sep 17 00:00:00 2001 From: zhangkun <> Date: Sat, 4 Dec 2021 13:27:36 +0800 Subject: [PATCH] issue fix for timer. --- hookq/consumer.go | 6 +----- hookq/example/consumer.go | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/hookq/consumer.go b/hookq/consumer.go index 452fcb2..8ed5950 100644 --- a/hookq/consumer.go +++ b/hookq/consumer.go @@ -122,14 +122,10 @@ func (c *Consumer) start() { c.process() if timer == nil { timer = time.NewTimer(c.tick) - } else { - if !timer.Stop() { - <-timer.C - } - timer.Reset(c.tick) } select { case <-timer.C: + timer.Reset(c.tick) case <-c.stopChan: c.submitWhenExit() if !timer.Stop() { diff --git a/hookq/example/consumer.go b/hookq/example/consumer.go index a37c153..3ad810e 100644 --- a/hookq/example/consumer.go +++ b/hookq/example/consumer.go @@ -114,6 +114,7 @@ func consumerMsg(c *cli.Context) error { signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM) select { case <-signalChan: + log.Println("received.exit.ctrl-c") consumer.Stop() consumer.Wait() log.Println("consumer.exit.by.signal")