咖啡伴侣

呆在上海
posts - 163, comments - 156, trackbacks - 0, articles - 2

golang 定时

Posted on 2013-10-10 15:07 oathleo 阅读(1653) 评论(0)  编辑  收藏 所属分类: Golang

 // (A)
time.AfterFunc(5 * time.Minute, func() {
    fmt.Printf("expired")
}

// (B) create a Timer object
timer := time.NewTimer(5 * time.Minute)
<-timer.C
fmt.Printf("expired")

// (C) time.After() returns timer.C internally
<-time.After(5 * time.Minute)
fmt.Printf("expired")

只有注册用户登录后才能发表评论。


网站导航: