async

package
v3.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForwardContext

func ForwardContext[T any](ctx context.Context, dst chan<- T, src <-chan T)

ForwardContext forwards all values from the src channel to the dst channel until the context is canceled or the src channel is closed.

func RangeContext

func RangeContext[T any](ctx context.Context, ch <-chan T, fn func(T))

RangeContext iterates over the given channel until the context is canceled or the channel is closed.

Types

type Abortable

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

Abortable collects groups of functions that can be aborted by calling Abort.

func (*Abortable) Abort

func (a *Abortable) Abort()

func (*Abortable) Do

func (a *Abortable) Do(ctx context.Context, fn func(context.Context))

type Group

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

Group is forked and improved version of "github.com/bradenaw/juniper/xsync.Group".

It manages a group of goroutines. The main change to original is posibility to wait passed function to finish without canceling it's context and adding PanicHandler.

func NewGroup

func NewGroup(ctx context.Context, panicHandler PanicHandler) *Group

NewGroup returns a Group ready for use. The context passed to any of the f functions will be a descendant of ctx.

func (*Group) Cancel

func (g *Group) Cancel()

Cancel is send to all of the spawn goroutines and ends periodic or trigger routines.

func (*Group) CancelAndWait

func (g *Group) CancelAndWait()

CancelAndWait cancels the context passed to any of the spawned goroutines and waits for all spawned goroutines to exit.

It is not safe to call Wait concurrently with any other method on g.

func (*Group) Finish

func (g *Group) Finish()

Finish will ends all periodic or polls routines. It will let currently running functions to finish (cancel is not sent).

It is not safe to call Wait concurrently with any other method on g.

func (*Group) Once

func (g *Group) Once(f func(ctx context.Context))

Once calls f once from another goroutine.

func (*Group) Periodic

func (g *Group) Periodic(
	interval time.Duration,
	jitter time.Duration,
	f func(ctx context.Context),
)

Periodic spawns a goroutine that calls f once per interval +/- jitter.

func (*Group) PeriodicOrTrigger

func (g *Group) PeriodicOrTrigger(
	interval time.Duration,
	jitter time.Duration,
	f func(ctx context.Context),
) func()

PeriodicOrTrigger spawns a goroutine which calls f whenever the returned function is called. If f is already running when triggered, f will run again immediately when it finishes. Also calls f when it has been interval+/-jitter since the last trigger.

func (*Group) Trigger

func (g *Group) Trigger(f func(ctx context.Context)) func()

Trigger spawns a goroutine which calls f whenever the returned function is called. If f is already running when triggered, f will run again immediately when it finishes.

func (*Group) WaitToFinish

func (g *Group) WaitToFinish()

WaitToFinish will ends all periodic or polls routines. It will wait for currently running functions to finish (cancel is not sent).

It is not safe to call Wait concurrently with any other method on g.

type PanicHandler

type PanicHandler interface {
	HandlePanic()
}

Jump to

Keyboard shortcuts

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