retry

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2018 License: MIT Imports: 5 Imported by: 0

README

retry

An expressive, flexible retry package for Go.

GoDoc

Features

  • Backoff helper
  • Retrying net.Listener wrapper

Examples

See retry_example_test.go

We're Hiring!

If you're a passionate Go developer, send your resume and/or GitHub link to jobs@coder.com.

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

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

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

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

import (
	"log"
	"net"

	"go.coder.com/retry"
)

func main() {
	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()

		// ...
	}
}
Output:

func (Listener) Accept

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

Jump to

Keyboard shortcuts

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