import "github.com/egdaemon/eg/runtime/x/wasi/egx"
Package egx holds experimental eg functionality, its api may change or move into the core runtime.
Retrier retries an operation when it fails. it is configured by chaining, each method returns a new Retrier and leaves the receiver unchanged.
egx.Retry(5).Delay(30 * time.Second).Run(op)
type Retrier struct {
// contains filtered or unexported fields
}
func Retry(attempts int) Retrier
Retry creates a Retrier that runs an operation at most attempts times, zero or less retries until the context ends. until configured it waits a second between attempts.
func (t Retrier) Backoff(s backoff.Strategy) Retrier
Backoff waits between attempts as the strategy dictates, it replaces any previous Delay or Backoff.
func (t Retrier) Cycle(first time.Duration, delays ...time.Duration) Retrier
Cycle waits first, then the remaining delays in order, between attempts, starting over at first once they are used up. it replaces any previous Delay or Backoff.
func (t Retrier) Delay(d time.Duration) Retrier
Delay waits d between attempts, it replaces any previous Delay or Backoff.
func (t Retrier) Exponential(scale time.Duration) Retrier
Exponential waits scale * 2^attempt between attempts, doubling after each failure, it replaces any previous Delay or Backoff. scale must not be zero.
func (t Retrier) Run(op eg.OpFn) eg.OpFn
Run creates the operation that runs op, retrying it when it fails. when the attempts are used up or the context ends the last error of op is returned.