mtchuyen / Golang-Tips

Tips in Golang programming
3 stars 2 forks source link

Golang Timer #18

Open mtchuyen opened 2 years ago

mtchuyen commented 2 years ago

https://vec.io/posts/release-golang-timer

drained := false
timer := time.NewTimer(period)
for {
    if !drained && !timer.Stop() {
        <-timer.C
    }
    drained = false
    timer.Reset(period)
    select {
    case <-other:
    case <-timer.C:
        drained = true
    }
}
mtchuyen commented 1 year ago

How Go timers are scheduled

https://www.sobyte.net/post/2022-03/go-timer/

https://www.kaoriya.net/blog/2019/12/19/

https://blog.csdn.net/pulong0748/article/details/107513252

https://blogtitle.github.io/go-advanced-concurrency-patterns-part-2-timers/

https://www.mail-archive.com/golang-nuts@googlegroups.com/msg35542.html

time.NewTimer(time.Minute): https://go101.org/article/concurrent-common-mistakes.html

https://groups.google.com/g/golang-nuts/c/t-vuX1mPn1c