Ticker
1. 用时间阻塞主程序,从而控制ticker
1 | func main() { |
输出结果
ticker1 at 2019-05-21 14:57:56.562591 +0800 CST m=+1.005065934
ticker1 at 2019-05-21 14:57:57.562549 +0800 CST m=+2.005016651
ticker1 at 2019-05-21 14:57:58.558122 +0800 CST m=+3.000583914
ticker1 at 2019-05-21 14:57:59.563205 +0800 CST m=+4.005660201
ticker1 at 2019-05-21 14:58:00.562585 +0800 CST m=+5.005033303
2. 用channel来精准控制次数
1 | func main() { |
输出结果
ticker2 at 2019-05-21 14:57:55.65885 +0800 CST m=+0.101330668
ticker2 at 2019-05-21 14:57:55.758399 +0800 CST m=+0.200878747