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

go 定时器

时间:2019-12-21 00:24:52      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:color   reset   for   font   时间   style   import   size   class   

package main

import (
    "time"
    "fmt"
)

func main()  {
    timer := time.NewTimer(3*time.Second)
    ok := timer.Reset(1*time.Second) //把以前3秒重置1s
    fmt.Println("ok=",ok)

    <-timer.C
    fmt.Println("时间到")
}


/*func main(){
    timer := time.NewTimer(3*time.Second)

    go func() {
         <- timer.C
         fmt.Println("子协程可以打印了,因为定时器的时间到了")
    }()

    timer.Stop()

    for{

    }
}*/

 

go 定时器

标签:color   reset   for   font   时间   style   import   size   class   

原文地址:https://www.cnblogs.com/dqh123/p/12075352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!