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 ¶
// Create a ticker that ticks on the minute with 1 second accuracy. t := cticker.New(time.Minute, time.Second) defer t.Stop() <-t.C // Process tick fmt.Println("tick")
Output: tick
func New ¶
New returns a new Ticker containing a channel that will send the time at d wall clock boundaries plus 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.
If the accuracy is too small, the ticker may not be able to tick at the requested time. Instead it will tick at the next available time after the target time, which should be within accuracy.
Stop the ticker to release its associated resources.