strategy

package
Version: v0.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package strategy defines repeater's strategy and implements some. Strategy result is a channel acting like time.Timer ot time.Tick

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	Duration time.Duration
	Repeats  int
	Factor   float64
	Jitter   bool
	// contains filtered or unexported fields
}

Backoff implements strategy.Interface for exponential-backoff it starts from 100ms (by default, if no Duration set) and goes in steps with last * math.Pow(factor, attempt) optional jitter randomize intervals a little bit.

func (*Backoff) Start

func (b *Backoff) Start(ctx context.Context) <-chan struct{}

Start returns channel, similar to time.Timer then publishing signals to channel ch for retries attempt. Closed ch indicates "done" event consumer (repeater) should stop it explicitly after completion

type FixedDelay

type FixedDelay struct {
	Repeats int
	Delay   time.Duration
}

FixedDelay implements strategy.Interface for fixed intervals up to max repeats

func (*FixedDelay) Start

func (s *FixedDelay) Start(ctx context.Context) <-chan struct{}

Start returns channel, similar to time.Timer then publishing signals to channel ch for retries attempt. can be terminated (canceled) via context.

type Interface

type Interface interface {
	Start(ctx context.Context) <-chan struct{}
}

Interface for repeater strategy. Returns channel with ticks

type Once

type Once struct{}

Once strategy eliminate repeats and makes a single try only

func (*Once) Start

func (s *Once) Start(ctx context.Context) <-chan struct{}

Start returns closed channel with a single element to prevent any repeats

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL