{"modulePath":"github.com/UnityTech/client-go","version":"v2.0.0+incompatible","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package wait\n\nPackage wait provides tools for polling or listening for changes to a condition.\n\n## Variables\n\n```go\nvar ErrWaitTimeout = errors.New(\"timed out waiting for the condition\")\n```\nErrWaitTimeout is returned when the condition exited without success.\n\n```go\nvar ForeverTestTimeout = time.Second * 30\n```\nFor any test of the style:\n\n\t...\n\t\u003c- time.After(timeout):\n\t   t.Errorf(\"Timed out\")\n\nThe value for timeout should effectively be \"forever.\" Obviously we don't want our tests to truly lock up forever, but 30s is long enough that it is effectively forever for the things that can slow down a run on a heavily contended machine (GC, seeks, etc), but not so long as to make a developer ctrl-c a test run if they do happen to break that test.\n\n```go\nvar NeverStop \u003c-chan struct{} = make(chan struct{})\n```\nNeverStop may be passed to Until to make it never stop.\n\n## Functions\n\n```go\nfunc ExponentialBackoff(backoff Backoff, condition ConditionFunc) error\n```\nExponentialBackoff repeats a condition check with exponential backoff.\n\nIt checks the condition up to Steps times, increasing the wait by multipling the previous duration by Factor.\n\nIf Jitter is greater than zero, a random amount of each duration is added (between duration and duration\\*(1+jitter)).\n\nIf the condition never returns true, ErrWaitTimeout is returned. All other errors terminate immediately.\n\n```go\nfunc Forever(f func(), period time.Duration)\n```\nForever calls f every period for ever.\n\nForever is syntactic sugar on top of Until.\n\n```go\nfunc Jitter(duration time.Duration, maxFactor float64) time.Duration\n```\nJitter returns a time.Duration between duration and duration + maxFactor \\* duration.\n\nThis allows clients to avoid converging on periodic behavior. If maxFactor is 0.0, a suggested default value will be chosen.\n\n```go\nfunc JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, stopCh \u003c-chan struct{})\n```\nJitterUntil loops until stop channel is closed, running f every period.\n\nIf jitterFactor is positive, the period is jittered before every run of f. If jitterFactor is not positive, the period is unchanged and not jitterd.\n\nIf slidingis true, the period is computed after f runs. If it is false then period includes the runtime for f.\n\nClose stopCh to stop. f may not be invoked if stop channel is already closed. Pass NeverStop to if you don't want it stop.\n\n```go\nfunc NonSlidingUntil(f func(), period time.Duration, stopCh \u003c-chan struct{})\n```\nNonSlidingUntil loops until stop channel is closed, running f every period.\n\nNonSlidingUntil is syntactic sugar on top of JitterUntil with zero jitter factor, with sliding = false (meaning the timer for period starts at the same time as the function starts).\n\n```go\nfunc Poll(interval, timeout time.Duration, condition ConditionFunc) error\n```\nPoll tries a condition func until it returns true, an error, or the timeout is reached.\n\nPoll always waits the interval before the run of 'condition'. 'condition' will always be invoked at least once.\n\nSome intervals may be missed if the condition takes too long or the time window is too short.\n\nIf you want to Poll something forever, see PollInfinite.\n\n```go\nfunc PollImmediate(interval, timeout time.Duration, condition ConditionFunc) error\n```\nPollImmediate tries a condition func until it returns true, an error, or the timeout is reached.\n\nPoll always checks 'condition' before waiting for the interval. 'condition' will always be invoked at least once.\n\nSome intervals may be missed if the condition takes too long or the time window is too short.\n\nIf you want to Poll something forever, see PollInfinite.\n\n```go\nfunc PollImmediateInfinite(interval time.Duration, condition ConditionFunc) error\n```\nPollImmediateInfinite tries a condition func until it returns true or an error\n\nPollImmediateInfinite runs the 'condition' before waiting for the interval.\n\nSome intervals may be missed if the condition takes too long or the time window is too short.\n\n```go\nfunc PollInfinite(interval time.Duration, condition ConditionFunc) error\n```\nPollInfinite tries a condition func until it returns true or an error\n\nPollInfinite always waits the interval before the run of 'condition'.\n\nSome intervals may be missed if the condition takes too long or the time window is too short.\n\n```go\nfunc PollUntil(interval time.Duration, condition ConditionFunc, stopCh \u003c-chan struct{}) error\n```\nPollUntil tries a condition func until it returns true, an error or stopCh is closed.\n\nPolUntil always waits interval before the first run of 'condition'. 'condition' will always be invoked at least once.\n\n```go\nfunc Until(f func(), period time.Duration, stopCh \u003c-chan struct{})\n```\nUntil loops until stop channel is closed, running f every period.\n\nUntil is syntactic sugar on top of JitterUntil with zero jitter factor and with sliding = true (which means the timer for period starts after the f completes).\n\n```go\nfunc WaitFor(wait WaitFunc, fn ConditionFunc, done \u003c-chan struct{}) error\n```\nWaitFor continually checks 'fn' as driven by 'wait'.\n\nWaitFor 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.\n\nIf 'fn' returns an error the loop ends and that error is returned, and if 'fn' returns true the loop ends and nil is returned.\n\nErrWaitTimeout will be returned if the channel is closed without fn ever returning true.\n\n## Types\n\n```go\ntype Backoff struct {\n\tDuration time.Duration // the base duration\n\tFactor   float64       // Duration is multipled by factor each iteration\n\tJitter   float64       // The amount of jitter applied each iteration\n\tSteps    int           // Exit with error after this many steps\n}\n```\nBackoff holds parameters applied to a Backoff function.\n\n```go\ntype ConditionFunc func() (done bool, err error)\n```\nConditionFunc returns true if the condition is satisfied, or an error if the loop should be aborted.\n\n```go\ntype WaitFunc func(done \u003c-chan struct{}) \u003c-chan struct{}\n```\nWaitFunc creates a channel that receives an item every time a test should be executed and is closed when the last test should be invoked.\n\n","path":"github.com/UnityTech/client-go/pkg/util/wait","name":"wait","synopsis":"Package wait provides tools for polling or listening for changes to a condition.","isRedistributable":true}
