util

package
v0.0.0-...-2fed64a Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: GPL-3.0, GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package util contains the redialer.

Index

Constants

View Source
const (
	Unconfigured redialerState = iota
	Redialing
	Stopped
)

Variables

This section is empty.

Functions

func SwapTimeouts

func SwapTimeouts(newTimeouts []time.Duration) (oldTimeouts []time.Duration)

For testing: change the default timeouts with the provided ones, returning the defaults (the idea being you reset them on test teardown).

func Timeouts

func Timeouts() []time.Duration

Retrieve the list of timeouts used for exponential backoff.

Types

type AutoRedialer

type AutoRedialer interface {
	Redial() uint32 // Redial keeps on calling Dial until it stops returning an error.
	Stop()          // Stop shuts down the given AutoRedialer, if it is still retrying.
}

An AutoRedialer's Redial() method retries its dialer's Dial() method until it stops returning an error. It does exponential backoff (optionally jittered).

func NewAutoRedialer

func NewAutoRedialer(dialer Dialer) AutoRedialer

Returns a stoppable AutoRedialer using the provided Dialer. If the Dialer is also a Jitterer, the backoff will be jittered.

type Dialer

type Dialer interface {
	Dial() error
}

A Dialer is an object that knows how to establish a connection, and where you'd usually want some kind of backoff if that connection fails.

type Jitterer

type Jitterer interface {
	Dialer
	Jitter(time.Duration) time.Duration
}

A Jitterer is a Dialer that wants to vary the backoff a little (to avoid a thundering herd, for example).

Jump to

Keyboard shortcuts

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