Golang absolute time timer

 Golang absolute time timer

for {
    tmNow := time.Now()
    nextTm := tmNow.Add(time.Minute * 1)
    nextTm = time.Date(nextTm.Year(), nextTm.Month(), nextTm.Day(), nextTm.Hour(), nextTm.Minute(), 0, 0, nextTm.Location())
    tm := time.NewTimer(nextTm.Sub(tmNow))
    log.Printf("next time is: [%s]\n", nextTm.Format("202111121000"))
    select {
        case <-tm.C:
        err := sync.Gather()
        if err != nil {
            log.Println(err)
        }
    }
}

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example