Documentation ¶
Overview ¶
Package clock provides aligned tickers. An aligned ticker is a channel of time.Time "ticks" similar to time.Ticker, but the ticks are even multiples of the requested period, and are delivered as shortly as possible after the clock reaching these timestamps. For example, with period=10s, the ticker ticks shortly after the passing of a unix timestamp that is a multiple of 10s, and the values returned are always these multiples. In my testing it practically ticks about .0001 to 0.0002 seconds later due to scheduling etc, but under high load, the delta may be larger. The ticks are always the "ideal" values
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlignedTickLossless ¶ added in v1.0.0
AlignedTickLossless returns an aligned ticker that waits for slow receivers, and backfills later as necessary to publish any pending ticks, at possibly a much more aggressive schedule. (keeps ticking until fully caught up) Note: clock jumps may still result in dropped ticks.
Types ¶
type RandomTicker ¶ added in v1.0.0
RandomTicker ticks at dur +- jitter
func NewRandomTicker ¶ added in v1.0.0
func NewRandomTicker(dur, jitt time.Duration, blocking bool) *RandomTicker
NewRandomTicker returns a new RandomTicker containing a channel that will send the time with a period specified by the duration and jitter arguments. It adjusts the intervals or drops ticks to make up for slow receivers. The duration and jitter must be greater than zero; if not, NewTicker will panic. duration must be >= jitter. Stop the ticker to release associated resources.
func (*RandomTicker) Stop ¶ added in v1.0.0
func (rt *RandomTicker) Stop()
Stop turns off the ticker. After Stop, no more ticks will be sent. Stop does not close the channel, to prevent a concurrent goroutine reading from the channel from seeing an erroneous "tick".