Documentation
¶
Overview ¶
Package backoff calculates delays; callers own waiting and cancellation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
Backoff calculates a delay for an attempt index. Retry uses index 1 for its first retry.
type Constant ¶
Constant returns a fixed delay; nonpositive periods produce zero. Concurrent calls are safe provided exported fields are not mutated concurrently.
func NewConstant ¶
NewConstant constructs a Constant delay policy.
type Exponential ¶
Exponential returns full jitter below min(Base * 2^index, Cap). Negative indices use zero; indices above 62 use 62. Nonpositive Base or Cap produces zero. Concurrent calls are safe provided exported fields are not mutated concurrently.
func NewExponential ¶
func NewExponential(base, cap time.Duration) *Exponential
NewExponential constructs a Exponential delay policy.
type Linear ¶
Linear returns Period times the index, saturated at the maximum duration. Nonpositive periods or indices produce zero. Concurrent calls are safe provided exported fields are not mutated concurrently.
func (*Linear) At ¶
At calculates the delay without waiting.
Example ¶
package main
import (
"fmt"
"time"
"github.com/alextanhongpin/core/sync/backoff"
)
func main() {
policy := backoff.NewLinear(100 * time.Millisecond)
for index := 1; index <= 3; index++ {
fmt.Println(policy.At(index))
}
}
Output: 100ms 200ms 300ms