retrier

package
v0.0.0-...-d2438c5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"
	"time"

	"github.com/spoke-d/thermionic/internal/clock"
	"github.com/spoke-d/thermionic/internal/retrier"
)

func main() {
	retry := retrier.New(clock.DefaultSleeper, 10, time.Second)
	err := retry.Run(func() error {
		return nil
	})

	switch {
	case err == nil:
		fmt.Println("success!")
	case retrier.ErrRetry(err):
		fmt.Println("deadline timeout")
	default:
		fmt.Println("other error")
	}

}
Output:

success!

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrRetry

func ErrRetry(err error) bool

ErrRetry checks if the error was because of too many retries.

Types

type Retrier

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

Retrier encapsulates the mechanism around retrying function

func New

func New(sleeper clock.Sleeper, amount int, duration time.Duration) *Retrier

New creates a Retrier with sane defaults

func (*Retrier) Run

func (r *Retrier) Run(fn func() error) error

Run executes the given function

Jump to

Keyboard shortcuts

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