wait

package
v0.6.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: BlueOak-1.0.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type TaperingTickerQueue added in v0.5.0

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

TaperingTickerQueue is a queue that will run Waiters according to a tapering- delay schedule. The first attempts will be more frequent, but if they are not successful, the delay between attempts will grow longer and longer up to a configurable maximum.

func NewTaperingTickerQueue added in v0.5.0

func NewTaperingTickerQueue(fastestInterval, slowestInterval time.Duration) *TaperingTickerQueue

NewTaperingTickerQueue is a constructor for a TaperingTicketQueue. The arguments fasterInterval and slowestInterval define how the Waiter attempt speed is tapered. Initially, attempts will be tried every fastestInterval. After fullSpeedTicks, the delays will be increased until it reaches slowestInterval (at fullyTapered).

func (*TaperingTickerQueue) Run added in v0.5.0

func (q *TaperingTickerQueue) Run(ctx context.Context)

Run runs the primary wait loop until the context is canceled.

func (*TaperingTickerQueue) Wait added in v0.5.0

func (q *TaperingTickerQueue) Wait(waiter *Waiter)

Wait attempts to run the (*Waiter).TryFunc until either 1) the function returns the value DontTryAgain, or 2) the function's Expiration time has passed. In the case of 2, the (*Waiter).ExpireFunc will be run.

type TickerQueue

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

TickerQueue is a Waiter manager that checks a function periodically until DontTryAgain is indicated.

func NewTickerQueue

func NewTickerQueue(recheckInterval time.Duration) *TickerQueue

NewTickerQueue is the constructor for a new TickerQueue.

func (*TickerQueue) Run

func (q *TickerQueue) Run(ctx context.Context)

Run runs the primary wait loop until the context is canceled.

func (*TickerQueue) Wait

func (q *TickerQueue) Wait(w *Waiter)

Wait attempts to run the (*Waiter).TryFunc until either 1) the function returns the value DontTryAgain, or 2) the function's Expiration time has passed. In the case of 2, the (*Waiter).ExpireFunc will be run.

type TryDirective added in v0.5.0

type TryDirective bool

TryDirective is a response that a Waiter's TryFunc can return to instruct the queue to continue trying or to quit.

const (
	// TryAgain, when returned from the Waiter's TryFunc, instructs the ticker
	// queue to try again after the configured delay.
	TryAgain TryDirective = false
	// DontTryAgain, when returned from the Waiter's TryFunc, instructs the
	// ticker queue to quit trying and quit tracking the Waiter.
	DontTryAgain TryDirective = true
)

type Waiter

type Waiter struct {
	// Expiration time is checked after the function returns TryAgain. If the
	// current time > Expiration, ExpireFunc will be run and the waiter will be
	// un-queued.
	Expiration time.Time
	// TryFunc is the function to run periodically until DontTryAgain is
	// returned or Waiter expires.
	TryFunc func() TryDirective
	// ExpireFunc is a function to run in the case that the Waiter expires.
	ExpireFunc func()
}

Waiter is a function to run every recheckInterval until completion or expiration. Completion is indicated when the TryFunc returns DontTryAgain. Expiration occurs when TryAgain is returned after Expiration time.

Jump to

Keyboard shortcuts

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