关于time.Ticker的一个问题

kiwi-yan · 2020-04-24 22:06:50 · 1183 次点击

godoc.org: 里面写到

NewTicker returns a new Ticker containing a channel that will send the time with a period specified by the duration argument. It adjusts the intervals or drops ticks to make up for slow receivers. The duration d must be greater than zero; if not, NewTicker will panic. Stop the ticker to release associated resources.

丢弃tick信息以适应反应慢的接收者, 你的情况应该影响不大吧

#1
更多评论

赞,因为粗略看了下源码,往发送ticker.C发送消息是开了goroutine去发的,然后ticker.C的大小是1,如果处理不及时的话,担心发生goroutine泄露;如果官方文档这么说的话就放心了,看来源码还是得仔细看看啊:)

#2