Golang <-time.After()在计时器过期前不会被垃圾回收

watermelo ·
``` func ProcessChannelMessages(ctx context.Context, in &lt;-chan string, idleCounter prometheus.Counter) { idleDuration := 5 * time.Minute tick:= time.Tick(idleDuration) for { select { case s, ok := &lt;-in: if !ok { return } // handle `s` case &lt;-tick: idleCounter.Inc() case &lt;-ctx.Done(): return } } } ``` 用这种周期性运行的方法,同样实现上面的功能,这个应该不会有内存泄露吧
#3
更多评论
buscoop
纸上得来终觉浅,绝知此事要躬行!
好人一生平安
#2