Documentation ¶
Index ¶
- func ForwardContext[T any](ctx context.Context, dst chan<- T, src <-chan T)
- func RangeContext[T any](ctx context.Context, ch <-chan T, fn func(T))
- type Abortable
- type Group
- func (g *Group) Cancel()
- func (g *Group) CancelAndWait()
- func (g *Group) Finish()
- func (g *Group) Once(f func(ctx context.Context))
- func (g *Group) Periodic(interval time.Duration, jitter time.Duration, f func(ctx context.Context))
- func (g *Group) PeriodicOrTrigger(interval time.Duration, jitter time.Duration, f func(ctx context.Context)) func()
- func (g *Group) Trigger(f func(ctx context.Context)) func()
- func (g *Group) WaitToFinish()
- type PanicHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ForwardContext ¶
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 ¶
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.
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) 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 ¶
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()
}