zoukankan      html  css  js  c++  java
  • 『Golang』—— 标准库之 time

    ...

     1 package main
     2 
     3 import (
     4     "fmt"
     5     "time"
     6 )
     7 
     8 func main() {
     9     time.AfterFunc(time.Millisecond*500, after_func)
    10 
    11     fmt.Println("Now, time.After 1 second")
    12     ac := time.After(time.Second)  //每次调用都会重新计时
    13     <-ac
    14 
    15     timer := time.NewTimer(time.Millisecond * 600)
    16 
    17     go func() {
    18         <-timer.C
    19         fmt.Println("...")
    20     }()
    21 
    22     timer.Stop()
    23     fmt.Println("timer stop")
    24 
    25     ticker := time.NewTicker(time.Millisecond * 200)
    26     go func() {
    27         for range ticker.C {
    28             fmt.Println("ticker arrive")
    29         }
    30     }()
    31 
    32     fmt.Println("Now, sleep 600 Milliseconds")
    33     time.Sleep(time.Millisecond * 600)
    34 
    35     ticker.Stop()
    36 }
    37 
    38 func after_func() {
    39     fmt.Println("I'm an after function")
    40 }

    ...

  • 相关阅读:
    c++ 01
    unix c 11
    unix c 10
    unix c 09
    unix c 08
    unix c 07
    unix c 06
    unix c 05
    unix c 04
    Petrozavodsk Summer Training Camp 2017
  • 原文地址:https://www.cnblogs.com/hadex/p/6685986.html
Copyright © 2011-2022 走看看