Documentation ¶
Overview ¶
Package xsync complements standard package sync.
- `WorkGroup` allows to spawn group of goroutines working on a common task.
Functionality provided by xsync package is also provided by Pygolang(*) in its standard package sync.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type WorkGroup ¶
type WorkGroup struct {
// contains filtered or unexported fields
}
WorkGroup represents group of goroutines working on a common task.
Use .Go() to spawn goroutines, and .Wait() to wait for all of them to complete, for example:
wg := xsync.NewWorkGroup(ctx) wg.Go(f1) wg.Go(f2) err := wg.Wait()
Every spawned function accepts context related to the whole work and derived from ctx used to initialize WorkGroup, for example:
func f1(ctx context.Context) error { ... }
Whenever a function returns error, the work context is canceled indicating to other spawned goroutines that they have to cancel their work. .Wait() waits for all spawned goroutines to complete and returns error, if any, from the first failed subtask.
NOTE if spawned function panics, the panic is currently _not_ propagated to .Wait().
WorkGroup is modelled after https://godoc.org/golang.org/x/sync/errgroup but is not equal to it.
func NewWorkGroup ¶
NewWorkGroup creates new WorkGroup working under ctx.
See WorkGroup documentation for details.