clock

package
v1.2.0-arch32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2025 License: AGPL-3.0 Imports: 2 Imported by: 0

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

func AlignedTickLossless(period time.Duration) <-chan time.Time

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.

func AlignedTickLossy

func AlignedTickLossy(period time.Duration) <-chan time.Time

AlignedTickLossy returns an aligned ticker that may drop ticks (if the consumer is slow or the clock jumps forward)

Types

type RandomTicker

type RandomTicker struct {
	C chan time.Time
	// contains filtered or unexported fields
}

RandomTicker ticks at dur +- jitter

func NewRandomTicker

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

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".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL