failover

package
v0.0.0-...-77610c5 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Unlicense Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = time.Second
)

Variables

View Source
var (
	// ErrFailover is the error to return from a Func to indicate failure to
	// obtain a result, and that the next available element should be tried.
	ErrFailover = errors.New("failover: fail over to next option. not an error")

	// ErrNoResult indicates that no result was available after performing all
	// available tries.
	ErrNoResult = errors.New("failover: no result available")
)

Functions

func Do

func Do(ctx context.Context, ch <-chan interface{}, f Func, opts *Options) (interface{}, error)

func DoSlice

func DoSlice(ctx context.Context, slice interface{}, f Func, opts *Options) (interface{}, error)

Types

type Func

type Func = func(context.Context, interface{}) (interface{}, error)

type Options

type Options struct {
	// Time before first failover attempt. If zero, DefaultTimeout is
	// used.
	InitialTimeout time.Duration

	// Time between failover attempts after the first. If zero, InitialTimeout
	// is used. To force all failovers to occur in parallel (no staggering), use
	// a trivially small duration, such as time.Nanosecond.
	StaggerInterval time.Duration
}

Jump to

Keyboard shortcuts

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