async

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: AGPL-3.0, ISC Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LockedScope

func LockedScope(l sync.Locker, action func())

func WaitGroup

func WaitGroup(ctx context.Context) (*sync.WaitGroup, error)

WaitGroup returns the set wait group

func WithFuture

func WithFuture(parent context.Context) (context.Context, *future.Future)

WithFuture return a future for reading a returned value from the child routine.

Note that the set future is only available for the first child routine, meaning it will not propagate recursively to lover level child routines. However, the child routine can setup its own future.

func WithWaitGroup

func WithWaitGroup(parent context.Context) (context.Context, *sync.WaitGroup)

WithWaitGroup sets and returns a wait group.

Note that the set wait group is propagated to all child routines.

Types

type JoinChan

type JoinChan chan struct{}

JoinChan is a signal channel in order to wait for a async Worker to finish.

func WithJoinChan

func WithJoinChan(parent context.Context) (context.Context, JoinChan)

WithJoinChan returns a join channel in order for the parent routine to wait for the child to finish.

Note that the set channel is only available for the first child routine, meaning it will not propagate recursively to lover level child routines. However, the child routine can setup its own join channel.

type Runner

type Runner func(ctx context.Context) future.Value

Runner is the task callback method. Will be invoked only once. Is is up to the user to add an infinite loop for a continues Worker. Must consume ctx.Done signal.

type Starter

type Starter interface {
	Start(context.Context)
}

type Worker

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

func MakeWorker

func MakeWorker(name string, runner Runner) Worker

MakeWorker creates a new Worker instance with the provided runnable object. Runner must be thread-safe.

func (Worker) Start

func (w Worker) Start(ctx context.Context)

Start initializes a separate go-routine for the worker instance Runner method. The runner can return a future.Value (see WithFuture).

Use context.Context for shutdown synchronization. For extra context options see contextKey.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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