Last active
October 20, 2017 13:26
-
-
Save tigercallme/d4a4ae90a180a80dfa5cfeae2ee8bc5a to your computer and use it in GitHub Desktop.
Go小技巧-使用for range time.Tick()固定间隔时间执行
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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