time.go 238 B

1234567891011121314151617181920
  1. package test
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. func TTime() {
  7. t := time.NewTicker(time.Second * 2)
  8. defer t.Stop()
  9. i := 0
  10. for i < 5 {
  11. select {
  12. case <-t.C:
  13. fmt.Println(i)
  14. i++
  15. }
  16. }
  17. fmt.Println("time.NewTicker(time.Second * 5)")
  18. }