Version: v0.0.0-...-070bfdb Latest Latest

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

Go to latest
Published: Mar 16, 2022 License: GPL-3.0 Imports: 2 Imported by: 7



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.

(*) https://pypi.org/project/pygolang



This section is empty.


This section is empty.


This section is empty.


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)
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

func NewWorkGroup(ctx context.Context) *WorkGroup

NewWorkGroup creates new WorkGroup working under ctx.

See WorkGroup documentation for details.

func (*WorkGroup) Go

func (g *WorkGroup) Go(f func(context.Context) error)

Go spawns new worker under workgroup.

See WorkGroup documentation for details.

func (*WorkGroup) Wait

func (g *WorkGroup) Wait() error

Wait waits for all spawned workers to complete.

It returns the error, if any, from the first failed worker. See WorkGroup documentation for details.

Source Files

Jump to

Keyboard shortcuts

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