首页 > 其他 > 详细

Tickers _ golang

时间:2015-03-18 13:45:40      阅读:278      评论:0      收藏:0      [点我收藏+]

Timers are for when you want to do something once in the future - tickers are for when you want to do something repeatedly at regular intervals. Here‘an example of a ticker that ticks periodically until we stop it

package main

import (
    "fmt"
    "time"
)

func main() {

    ticker := time.NewTicker(time.Millisecond * 500)
    go func() {
        for t := range ticker.C {
            fmt.Println("Tick at", t)
        }
    }()

    time.Sleep(time.Millisecond * 1500)
    ticker.Stop()
    fmt.Println("Ticker stopped")
}
Tick at 2015-03-18 13:20:55.55095115 +0800 CST
Tick at 2015-03-18 13:20:56.050762096 +0800 CST
Tick at 2015-03-18 13:20:56.550295916 +0800 CST
Ticker stopped

总结  : 

  1 : ....

Tickers _ golang

原文:http://www.cnblogs.com/jackkiexu/p/4346916.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!