interval

package
v1.2.3-fred.10 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Duration is the duration on which the interval "ticks" (if a jitter is
	// applied, this represents the upper bound of the range).
	Duration time.Duration

	// FirstDuration is an optional special duration to be used for the first
	// "tick" of the interval.  This duration is not jittered.
	FirstDuration time.Duration

	// Jitter is an optional jitter to be applied to each step of the interval.
	// It is usually preferable to use a smaller jitter (e.g. NewSeventhJitter())
	// for this parameter, since periodic operations are typically costly and the
	// effect of the jitter is cumulative.
	Jitter retryutils.Jitter
}

Config configures an interval. The only required parameter is the Duration field which *must* be a positive duration.

type Interval

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

Interval functions similarly to time.Ticker, with the added benefit of being able to specify a custom duration for the first "tick", and an optional per-tick jitter. When attempting to stagger periodic operations it is recommended to apply a large jitter to the first duration, and provide a small jitter for the per-tick jitter. This will ensure that operations started at similar times will have varying initial interval states, while minimizing the amount of extra work introduced by the per-tick jitter.

func New

func New(cfg Config) *Interval

New creates a new interval instance. This function panics on non-positive interval durations (equivalent to time.NewTicker).

func NewNoop

func NewNoop() *Interval

NewNoop creates a new interval that will never fire.

func (*Interval) Next

func (i *Interval) Next() <-chan time.Time

Next is the channel over which the intervals are delivered.

func (*Interval) Reset

func (i *Interval) Reset()

Reset resets the interval without pausing it (i.e. it will now fire in jitter(duration) regardless of current timer progress).

func (*Interval) Stop

func (i *Interval) Stop()

Stop permanently stops the interval. Note that stopping an interval does not close its output channel. This is done in order to prevent concurrent stops from generating erroneous "ticks" and is consistent with the behavior of time.Ticker.

Jump to

Keyboard shortcuts

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