wait

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT, Apache-2.0 Imports: 3 Imported by: 0

README

Wait

Files in this package are based on https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/apimachinery/pkg/util/wait so I can have a stable API and not need to import a bunch of external dependencies.

Thank you to the developers who made these wonderful utilities.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PollUntilContextCancel

func PollUntilContextCancel(ctx context.Context, interval time.Duration, immediate bool, condition ConditionWithContextFunc) error

PollUntilContextCancel tries a condition func until it returns true, an error, or the context is cancelled or hits a deadline. condition will be invoked after the first interval if the context is not cancelled first. The returned error will be from ctx.Err(), the condition's err return value, or nil. If invoking condition takes longer than interval the next condition will be invoked immediately. When using very short intervals, condition may be invoked multiple times before a context cancellation is detected. If immediate is true, condition will be invoked before waiting and guarantees that condition is invoked at least once, regardless of whether the context has been cancelled.

func PollUntilContextTimeout

func PollUntilContextTimeout(ctx context.Context, interval, timeout time.Duration, immediate bool, condition ConditionWithContextFunc) error

PollUntilContextTimeout will terminate polling after timeout duration by setting a context timeout. This is provided as a convenience function for callers not currently executing under a deadline and is equivalent to:

deadlineCtx, deadlineCancel := context.WithTimeout(ctx, timeout)
err := PollUntilContextCancel(deadlineCtx, interval, immediate, condition)

The deadline context will be cancelled if the Poll succeeds before the timeout, simplifying inline usage. All other behavior is identical to PollUntilContextCancel.

Types

type ConditionWithContextFunc

type ConditionWithContextFunc func(context.Context) (done bool, err error)

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.

Jump to

Keyboard shortcuts

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