backoff

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package backoff provides retry backoff strategies for the outbox relay.

Index

Constants

View Source
const Stop = time.Duration(-1)

Stop is the sentinel a NextBackOff-style source returns to mean "no more retries"; it matches github.com/cenkalti/backoff.Stop. Adapters map it to 0.

Variables

View Source
var Default = Exp(100*time.Millisecond, 30*time.Second, true)

Default is exponential 100ms -> 30s with full jitter.

Functions

This section is empty.

Types

type Backoff

type Backoff func(attempt int) time.Duration

Backoff returns the delay before the retry that follows the given attempt number. attempt is 1-based: the delay after the first failed attempt is Backoff(1).

func Exp

func Exp(base, maxDelay time.Duration, jitter bool) Backoff

Exp returns an exponential backoff: base doubled each attempt, capped at maxDelay (0 = no cap). With jitter the result is uniform in [0, computed].

func FromNextBackOff

func FromNextBackOff(newB func() NextBackOffer) Backoff

FromNextBackOff adapts a cenkalti/backoff-style source to a Backoff. newB must return a fresh instance on each call; it is advanced `attempt` times to obtain that attempt's delay. A Stop result yields 0.

ob.WithRetryBackoff(backoff.FromNextBackOff(func() backoff.NextBackOffer {
    return cbackoff.NewExponentialBackOff()
}))

func FromNexter

func FromNexter(newB func() Nexter) Backoff

FromNexter adapts a sethvargo/go-retry-style source to a Backoff. newB must return a fresh instance on each call; it is advanced `attempt` times. A stop signal yields 0.

func (Backoff) Delay

func (b Backoff) Delay(attempt int) time.Duration

Delay lets a Backoff also satisfy interfaces that expect a Delay(attempt) method, and reads naturally at call sites.

type NextBackOffer

type NextBackOffer interface {
	NextBackOff() time.Duration
}

NextBackOffer matches the retry method of github.com/cenkalti/backoff (BackOff.NextBackOff). *backoff.ExponentialBackOff and friends satisfy it.

type Nexter

type Nexter interface {
	Next() (time.Duration, bool)
}

Nexter matches the Backoff interface of github.com/sethvargo/go-retry (Next() (time.Duration, bool)).

Jump to

Keyboard shortcuts

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