retry

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: MIT Imports: 2 Imported by: 34

README

retry

An exponentially backing off retry package for Go.

GoDoc

go get github.com/coder/retry

Features

  • A for loop experience instead of closures
  • Only 2 exported methods
  • No external dependencies

Examples

Wait for connectivity to google.com, checking at most once every second.

func pingGoogle(ctx context.Context) error {
	var err error
    r := retry.New(time.Second, time.Second*10)
    for r.Wait(ctx) {
        _, err = http.Get("https://google.com")
        if err != nil {
	        continue		
        }   
        break
    }
    return err
}

Wait for connectivity to google.com, checking at most 10 times.

func pingGoogle(ctx context.Context) error {
    var err error
    r := retry.New(time.Second, time.Second*10)
    for n := 0; r.Wait(ctx) && n < 10; n++ {
        _, err = http.Get("https://google.com")
        if err != nil {
            continue
        }
		break
	}
    return err
}

Documentation

Overview

Package retry runs a failable function until it succeeds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Retrier added in v1.3.0

type Retrier struct {
	// contains filtered or unexported fields
}

Retrier implements an exponentially backing off retry instance. Use New instead of creating this object directly.

func New

func New(floor, ceil time.Duration) *Retrier

New creates a retrier that exponentially backs off from floor to ceil pauses.

func (*Retrier) Wait added in v1.3.0

func (r *Retrier) Wait(ctx context.Context) bool

Jump to

Keyboard shortcuts

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