retry: go.coder.com/retry Index | Examples | Files

package retry

import "go.coder.com/retry"

Package retry contains utilities for retrying an action until it succeeds.

Index

Examples

Package Files

backoff.go doc.go listener.go

type Backoff Uses

type Backoff struct {
    // These two fields must be initialized.
    // Floor should never be greater than or equal
    // to the Ceil in general. If it is, the Backoff
    // will stop backing off and just sleep for the Floor
    // in Wait().
    Floor time.Duration
    Ceil  time.Duration
    // contains filtered or unexported fields
}

Backoff holds state about a backoff loop in which there should be a delay in iterations.

func (*Backoff) Wait Uses

func (b *Backoff) Wait(ctx context.Context) error

Wait should be called at the end of the loop. It will sleep for the necessary duration before the next iteration of the loop can begin. If the context is cancelled, Wait will return early with a non-nil error.

type Listener Uses

type Listener struct {
    LogTmpErr func(err error)
    net.Listener
}

Code:

l, err := net.Listen("tcp", "localhost:0")
if err != nil {
    log.Fatalf("failed to listen: %v", err)
}
defer l.Close()

l = retry.Listener{
    Listener: l,
}

for {
    c, err := l.Accept()
    if err != nil {
        log.Fatalf("failed to accept: %v", err)
    }
    defer c.Close()

    // ...
}

func (Listener) Accept Uses

func (l Listener) Accept() (net.Conn, error)

Package retry imports 5 packages (graph). Updated 2018-10-04. Refresh now. Tools for package owners.