async

package
v0.0.0-...-f1c6d0e Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackFn

type CallbackFn func() error

CallbackFn is a callback function signature.

Since Go does not (yet) have generics, it allows encapsulating references to specific types in the caller.

type DoFn

type DoFn func(context.Context) CallbackFn

DoFn is the basic unit of async execution.

type Messenger

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

Messenger is held by clients who wish to execute something asynchronously.

func (*Messenger) DoAsync

func (m *Messenger) DoAsync(ctx context.Context, f DoFn) <-chan CallbackFn

DoAsync executes the DoFn asynchronously, returning a channel which will have the callback function provided upon completion.

If the Messenger is already closed, a callback function returning an error is given.

func (*Messenger) DoBlocking

func (m *Messenger) DoBlocking(ctx context.Context, f DoFn) error

DoBlocking executes the function in the Queue queue, blocks until a callback is received, then executes the callback and returns any errors.

func (*Messenger) NowAndPeriodically

func (m *Messenger) NowAndPeriodically(d time.Duration, f PeriodicFn, l *zerolog.Logger)

func (*Messenger) Periodically

func (m *Messenger) Periodically(d time.Duration, f PeriodicFn, l *zerolog.Logger)

type PeriodicFn

type PeriodicFn func(context.Context) error

Periodic functions are ran intermittently, and errors returned from them result in logged error messages.

type Queue

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

Queue gracefully facilitates fan-in message passing.

func NewQueue

func NewQueue(ctx context.Context) *Queue

func (*Queue) Messenger

func (a *Queue) Messenger() *Messenger

Messenger obtains a new handle for clients to add work to the async queue.

If the Queue pool is already closed, nil is returned.

func (*Queue) Start

func (a *Queue) Start() error

Start begins the asynchronous processing.

It must be called at the beginning of the Queue lifetime. Starting after a call to Stop is not supported as all Messengers become invalidated.

func (*Queue) Stop

func (a *Queue) Stop()

Stop ends asynchronous processing gracefully, returning after all processing is completed.

Invalidates the Messengers produced by this Queue.

Jump to

Keyboard shortcuts

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