Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Periodic ¶
Periodic executes fn on every period. Periodic returns if the context is cancelled. The underlying ticket adjusts the intervals or drops ticks to make up for slow runs of fn. If fn is active, Periodic will only return when fn has finished. The period must be greater than 0, otherwise Periodic panics.
If fn returns an Error, then the loop is stopped and the functions error is returned directly. On normal termination the contexts reported error will be reported.
func RetryUntil ¶ added in v0.3.0
RetryUntil executes fn periodically until the function no longer returns an error, or the timeout has elapsed, or the context is canceled. If the timeout has elapsed and fn still returns an error, RetryUntil wraps the original error from fn and returns it. If fn no longer returns an error, RetryUntil returns nil.
Example:
err := RetryUntil(context.Background(), 1 * time.Second, 10 * time.Millisecond, func(ctx context.Contect) error { actual := getCount(ctx) if actual != 3 { return fmt.Errorf("expected 3 items, got %d", actual) } }) if err != nil { fmt.Printf("RetryUntil has failed: %+v\n", err) } else { fmt.Println("good things come to those who wait") }
func Wait ¶
Wait blocks for the configuration duration or until the passed context signal canceling. Wait return ctx.Err() if the context got cancelled early. If the duration has passed without the context being cancelled, Wait returns nil.
Example:
fmt.Printf("wait for 5 seconds...") if err := Wait(ctx, 5 * time.Second); err != nil { fmt.Printf("shutting down") return err } fmt.Println("done")
Types ¶
This section is empty.