Documentation ¶
Index ¶
- Variables
- func BackoffUntil(f func(), backoff backoffManager, sliding bool, stopCh <-chan struct{})
- func ForWithContext(ctx context.Context, wait WithContextFunc, fn ConditionWithContextFunc) error
- func Jitter(duration time.Duration, maxFactor float64) time.Duration
- func JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, ...)
- func PollImmediateUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error
- func PollImmediateUntilWithContext(ctx context.Context, interval time.Duration, ...) error
- func Until(f func(), period time.Duration, stopCh <-chan struct{})
- type ConditionFunc
- type ConditionWithContextFunc
- type WithContextFunc
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 BackoffUntil ¶
func BackoffUntil(f func(), backoff backoffManager, sliding bool, stopCh <-chan struct{})
BackoffUntil loops until stop channel is closed, run f every duration given by BackoffManager.
If sliding is true, the period is computed after f runs. If it is false then period includes the runtime for f.
func ForWithContext ¶
func ForWithContext(ctx context.Context, wait WithContextFunc, fn ConditionWithContextFunc) error
ForWithContext continually checks 'fn' as driven by 'wait'.
ForWithContext 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 the channel is closed and 'fn' returns false without error, ForWithContext returns ErrWaitTimeout.
If 'fn' returns an error the loop ends and that error is returned. If 'fn' returns true the loop ends and nil is returned.
context.Canceled will be returned if the ctx.Done() channel is closed without fn ever returning true.
When the ctx.Done() channel is closed, because the golang `select` statement is "uniform pseudo-random", the `fn` might still run one or multiple times, though eventually `ForWithContext` will return.
func Jitter ¶
Jitter returns a time.Duration between duration and duration + maxFactor * duration.
This allows clients to avoid converging on periodic behavior. If maxFactor is 0.0, a suggested default value will be chosen.
func JitterUntil ¶
func JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, stopCh <-chan struct{})
JitterUntil loops until stop channel is closed, running f every period.
If jitterFactor is positive, the period is jitter before every run of f. If jitterFactor is not positive, the period is unchanged and not jitter.
If sliding is true, the period is computed after f runs. If it is false then period includes the runtime for f.
Close stopCh to stop. f may not be invoked if stop channel is already closed. Pass NeverStop to if you don't want it stop.
func PollImmediateUntil ¶
func PollImmediateUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error
PollImmediateUntil tries a condition func until it returns true, an error or stopCh is closed.
PollImmediateUntil runs the 'condition' before waiting for the interval. 'condition' will always be invoked at least once.
func PollImmediateUntilWithContext ¶
func PollImmediateUntilWithContext(ctx context.Context, interval time.Duration, condition ConditionWithContextFunc) error
PollImmediateUntilWithContext tries a condition func until it returns true, an error or the specified context is cancelled or expired.
PollImmediateUntilWithContext runs the 'condition' before waiting for the interval. 'condition' will always be invoked at least once.
Types ¶
type ConditionFunc ¶
ConditionFunc returns true if the condition is satisfied, or an error if the loop should be aborted.
func (ConditionFunc) WithContext ¶
func (cf ConditionFunc) WithContext() ConditionWithContextFunc
WithContext converts a ConditionFunc into a ConditionWithContextFunc
type ConditionWithContextFunc ¶
ConditionWithContextFunc returns true if the condition is satisfied, or an error if the loop should be aborted.
The caller passes along a context that can be used by the condition function.
type WithContextFunc ¶
WithContextFunc creates a channel that receives an item every time a test should be executed and is closed when the last test should be invoked.
When the specified context gets cancelled or expires the function stops sending item and returns immediately.