『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 }
...
HADEX_ FROM HELL.