【英文】Go语言的Timer定时器

Preface

Notes on studying Timer timers in Go language

Delaying using the built-in channel in Timer

  • Timer has a built-in channel that blocks when getting data from it until the timer ends.

time.Second: Delay time

1
2
3
4
5
6
7
8
package main

import "time"

func main() {
var timer = time.NewTimer(time.Second)
<-timer.C
}

Delaying directly using the After function

1
2
3
4
5
6
7
package main

import "time"

func main() {
<-timer.After(time.Second)
}

Completed

References

Bilibili - Guo Hongzhi-Lao Guo