Documentation ¶
Overview ¶
Package wait provides tools for polling or listening for changes to a condition.
Index ¶
- Variables
- func Jitter(duration time.Duration, maxFactor float64) time.Duration
- func Poll(interval, timeout time.Duration, condition ConditionFunc) error
- func PollImmediate(interval, timeout time.Duration, condition ConditionFunc) error
- func PollInfinite(interval time.Duration, condition ConditionFunc) error
- func WaitFor(wait WaitFunc, fn ConditionFunc) error
- type ConditionFunc
- type WaitFunc
Constants ¶
This section is empty.
Variables ¶
var ErrWaitTimeout = errors.New("timed out waiting for the condition")
ErrWaitTimeout is returned when the condition exited without success
Functions ¶
func Jitter ¶
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 v0.19.0
func PollImmediate(interval, timeout time.Duration, condition ConditionFunc) error
func PollInfinite ¶ added in v0.19.0
func PollInfinite(interval time.Duration, condition ConditionFunc) error
PollInfinite polls forever.
func WaitFor ¶
func WaitFor(wait WaitFunc, fn ConditionFunc) 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 ConditionFunc ¶
ConditionFunc returns true if the condition is satisfied, or an error if the loop should be aborted.