timer

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomDuration

func RandomDuration(max time.Duration) time.Duration

RandomDuration creates a random duration from 0 to the given max duration

Types

type ErrSleeperCancelled added in v0.1.12

type ErrSleeperCancelled struct{}

ErrSleeperCancelled returned when a sleeper is cancelled early

func (*ErrSleeperCancelled) Error added in v0.1.12

func (e *ErrSleeperCancelled) Error() string

type NextSleepDuration

type NextSleepDuration func(sleepDuration time.Duration, count int) time.Duration

NextSleepDuration provided to set a custom func to determine the next sleep duration

type Sleeper

type Sleeper struct {
	// contains filtered or unexported fields
}

Sleeper is a more complex version of the base timer

func NewCustomSleeper

func NewCustomSleeper(sleepDuration time.Duration, sleepFunc NextSleepDuration) *Sleeper

NewCustomSleeper returns a sleeper that will use a custom sleeper function to get the interval duration

func NewExponentialSleeper

func NewExponentialSleeper(sleepDuration time.Duration, alpha float64) *Sleeper

NewExponentialSleeper returns a sleeper that will sleep with an exponentially increasing interval useful for exponential backoff

func NewLinearSleeper

func NewLinearSleeper(sleepDuration time.Duration, alpha int64) *Sleeper

NewLinearSleeper returns a sleeper that will sleep with an linearly increasing interval useful for linear backoff

func NewSleeper

func NewSleeper(sleepDuration time.Duration) *Sleeper

NewSleeper returns a sleeper that will sleep for the given sleep duration every time Sleep() is called

func (*Sleeper) Cancel

func (s *Sleeper) Cancel()

Cancel cancels the sleeper, causing any running sleeper routines to return

func (*Sleeper) Sleep

func (s *Sleeper) Sleep() <-chan error

Sleep returns a channel that will return a ErrSleeperCancelled error if context is cancelled before the next sleep interval completes, nil otherwise

func (*Sleeper) WithAddRandom

func (s *Sleeper) WithAddRandom(add time.Duration) *Sleeper

WithAddRandom waits for an additional duration from 0 to the given duration every interval

func (*Sleeper) WithContext

func (s *Sleeper) WithContext(ctx context.Context) *Sleeper

WithContext adds an external context to this sleeper

Jump to

Keyboard shortcuts

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