backoff

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 4 Imported by: 0

README

Backoff

Test codecov Go Report Card Go Reference

A Full-Jitter exponential backoff helper for Go.

The algorithm used to compute the randomized delay mainly comes from the Full-Jitter exponential backoff strategy described in the AWS Architecture Blog post Exponential Backoff and Jitter, ensuring evenly distributed retries without synchronized bursts.

Features

  • Extremely easy to use
  • Zero third-party dependencies

Installation

To use this project programmatically, go get it:

go get github.com/aofei/backoff

Community

If you have any questions or ideas about this project, feel free to discuss them here.

Contributing

If you would like to contribute to this project, please submit issues here or pull requests here.

When submitting a pull request, please make sure its commit messages adhere to Conventional Commits 1.0.0.

License

This project is licensed under the MIT License.

Documentation

Overview

Package backoff implements a Full-Jitter exponential backoff helper for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

func After(base, cap time.Duration, attempt int) <-chan time.Time

After returns a channel that will deliver the current time after the delay produced by Duration. It is shorthand for time.After(Duration(base, cap, attempt)).

func Attempts added in v1.1.0

func Attempts(ctx context.Context, maxAttempts int, base, cap time.Duration) iter.Seq[int]

Attempts returns an iterator that yields zero-based attempts and waits for the delay from After between successive attempts.

func Duration

func Duration(base, cap time.Duration, attempt int) time.Duration

Duration returns a randomized exponential-backoff delay. The delay is chosen uniformly from [0, min(cap, base*2^attempt)).

func Sleep

func Sleep(base, cap time.Duration, attempt int)

Sleep blocks for the delay produced by Duration. It is shorthand for time.Sleep(Duration(base, cap, attempt)).

Types

This section is empty.

Jump to

Keyboard shortcuts

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