wait

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2016 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package wait provides tools for polling or listening for changes to a condition.

Index

Constants

This section is empty.

Variables

View Source
var ErrWaitTimeout = errors.New("timed out waiting for the condition")

ErrWaitTimeout is returned when the condition exited without success

Functions

func ExponentialBackoff added in v1.0.7

func ExponentialBackoff(backoff Backoff, condition ConditionFunc) error

ExponentialBackoff repeats a condition check up to steps times, increasing the wait by multipling the previous duration by factor. If jitter is greater than zero, a random amount of each duration is added (between duration and duration*(1+jitter)). If the condition never returns true, ErrWaitTimeout is returned. All other errors terminate immediately.

func Jitter

func Jitter(duration time.Duration, maxFactor float64) time.Duration

Jitter returns a time.Duration between duration and duration + maxFactor * duration, to allow clients to avoid converging on periodic behavior. If maxFactor is 0.0, a suggested default value will be chosen.

func Poll

func Poll(interval, timeout time.Duration, condition ConditionFunc) error

Poll tries a condition func until it returns true, an error, or the timeout is reached. condition will always be invoked at least once but some intervals may be missed if the condition takes too long or the time window is too short. If you want to Poll something forever, see PollInfinite. Poll always waits the interval before the first check of the condition.

func PollImmediate added in v1.0.7

func PollImmediate(interval, timeout time.Duration, condition ConditionFunc) error

func PollInfinite added in v1.0.7

func PollInfinite(interval time.Duration, condition ConditionFunc) error

PollInfinite polls forever.

func WaitFor

func WaitFor(wait WaitFunc, fn ConditionFunc, done <-chan struct{}) error

WaitFor gets a channel from wait(), and then invokes fn once for every value placed on the channel and once more when the channel is closed. If fn returns an error the loop ends and that error is returned, and if fn returns true the loop ends and nil is returned. ErrWaitTimeout will be returned if the channel is closed without fn ever returning true.

Types

type Backoff added in v1.0.7

type Backoff struct {
	Duration time.Duration
	Factor   float64
	Jitter   float64
	Steps    int
}

Backoff is parameters applied to a Backoff function.

type ConditionFunc

type ConditionFunc func() (done bool, err error)

ConditionFunc returns true if the condition is satisfied, or an error if the loop should be aborted.

type WaitFunc

type WaitFunc func(done <-chan struct{}) <-chan struct{}

WaitFunc creates a channel that receives an item every time a test should be executed and is closed when the last test should be invoked.

Jump to

Keyboard shortcuts

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