jitter

package
v1.4.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

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
	// contains filtered or unexported fields
}

func NewTicker

func NewTicker(duration time.Duration, jitter time.Duration) *Ticker

NewTicker creates a Ticker that works similar to time.Ticker, but sends the time with a period specified by `duration` adjusted by a pseudorandom jitter in the range of [duration-jitter, duration+jitter). Following the behavior of time.Ticker, we use a 1-buffer channel, so if the client falls behind while reading, we'll drop ticks on the floor until the client catches up. Callers have to make sure that both duration and the [d-j, d+j) intervals are valid positive int64 values (non-negative and non-overflowing). Use Stop to release associated resources and the Reset methods to modify the duration and jitter.

func (*Ticker) Reset

func (t *Ticker) Reset(d time.Duration)

Reset stops the Ticker, resets its base duration to the specified argument and re-calculates the period with a jitter. The next tick will arrive after the new period elapses.

func (*Ticker) ResetJitter

func (t *Ticker) ResetJitter(d time.Duration)

Reset stops the Ticker, resets its jitter to the specified argument and re-calculates the period with the new jitter. The next tick will arrive after the new period elapses.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop turns off the Ticker; no more ticks will be sent. Stop does not close Ticker's channel, to prevent a concurrent goroutine from seeing an erroneous "tick".

Jump to

Keyboard shortcuts

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