Documentation ¶
Overview ¶
Package cticker provides a ticker which ticks according to wall clock instead of monotonic clock. It is reliable under both 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.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ticker ¶
type Ticker struct { C <-chan time.Time // The channel on which ticks are delivered. // contains filtered or unexported fields }
Ticker holds a channel that delivers `ticks` on wall clock boundaries. Unlike time.Ticker it will fire early if the clock is adjusted to an earlier time, therefore it can be used for events which need to trigger on wall clock boundaries e.g. every minute on the minute.
Example ¶
TODO(steve): remove this nolint when go tool vet is fixed. nolint: vet
t := cticker.New(time.Minute, time.Second) for tick := range t.C { // Process tick fmt.Println("tick:", tick) }
Output:
func New ¶
New returns a new Ticker containing a channel that will send the time at d wall clock boundaries plus or minus accuracy. It will drop ticks to make up for slow receivers. The duration d must be greater than zero; if not, NewTicker will panic. The accuracy must be less than d; it not, NewTicker will panic. Stop the ticker to release its associated resources.