jitter

package
v3.10.66 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 3 Imported by: 4

Documentation

Overview

Package jitter provides a random jitter

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Random

func Random(d time.Duration) time.Duration

Random returns a random time to jitter with max cap specified

func RandomInterval added in v3.9.5

func RandomInterval(min, max time.Duration) time.Duration

Types

type Ticker

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

Ticker is similar to time.Ticker but ticks at random intervals between the min and max duration values (stored internally as int64 nanosecond counts).

func NewTicker

func NewTicker(min, max time.Duration) *Ticker

NewTicker returns a pointer to an initialized instance of the Ticker. Min and max are durations of the shortest and longest allowed ticks. Ticker will run in a goroutine until explicitly stopped.

func NewTickerContext added in v3.9.3

func NewTickerContext(ctx context.Context, min, max time.Duration) *Ticker

NewTickerContext returns a pointer to an initialized instance of the Ticker. It works like NewTicker except that it has ability to close via context. Also it works fine with context.WithTimeout to handle max time to run ticker.

func (*Ticker) Stop

func (ticker *Ticker) Stop()

Stop terminates the ticker goroutine and closes the C channel.

Jump to

Keyboard shortcuts

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