码迷,mamicode.com
首页 > 其他好文 > 详细

Tickers _ golang

时间:2015-03-18 13:48:35      阅读:125      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!