Skip to content

Instantly share code, notes, and snippets.

@tigercallme
Last active October 20, 2017 13:26
Show Gist options
  • Save tigercallme/d4a4ae90a180a80dfa5cfeae2ee8bc5a to your computer and use it in GitHub Desktop.
Save tigercallme/d4a4ae90a180a80dfa5cfeae2ee8bc5a to your computer and use it in GitHub Desktop.
Go小技巧-使用for range time.Tick()固定间隔时间执行
for range time.Tick(30 * time.Millisecond) {
doSomthing()
}
//time.Tick()返回的是一个channel,每隔指定的时间会有数据从channel中出来,
//for range不仅能遍历map,slice,array还能取出channel中数据,range前面可以不用变量接收,
//所以可以简写成上面的形式。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment