go-cticker is a Go library that provides a ticker which ticks according to wall clock and is reliable under clock drift and clock adjustments; that is if you ask it to tick on the minute it will ensure that it does so even if the underlying clock is inaccurate or gets adjusted.
- Reliable under clock drift.
- Reliable under clock adjustments.
go get -u github.com/multiplay/go-cticker
Using go-cticker is very much like time.NewTicker with the addition of an accuracy and start time.
The following creates a ticker which ticks on the minute according the hosts wall clock with an accuracy of plus or minus one second.
package main
import (
"fmt"
"time"
"github.com/multiplay/go-cticker"
)
func main() {
t := cticker.New(time.Minute, time.Second)
for tick := range t.C {
// Process tick
fmt.Println("tick:", tick)
}
}
go-cticker is available under the BSD 2-Clause License.