wait

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: BlueOak-1.0.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// These constants are used for a Waiter to inform the TickerQueue whether to
	// run again or not.
	TryAgain     = false
	DontTryAgain = true
)

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 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 (w *TickerQueue) Run(ctx context.Context)

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

func (*TickerQueue) Wait

func (w *TickerQueue) Wait(settings *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 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 every recheckInterval until DontTryAgain is
	// returned or Waiter expires.
	TryFunc func() bool
	// 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