2016-08-09 17:22
浏览 53


I am new to Go and started learning recently. I have come across tickers and timers. In the tickers, we can create a ticker in two ways

throttler := time.Tick(time.Millisecond * 50)
<- throttler

throttler := time.NewTicker(time.Millisecond * 500)
<- throttler.C

What is the difference between them other than syntax?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doucuoyan0426 2016-08-09 17:24

    From the time.Tick documentation:

    Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. While Tick is useful for clients that have no need to shut down the Ticker, be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks".

    打赏 评论

相关推荐 更多相似问题