syncutil

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 4 Imported by: 3

Documentation

Overview

Package syncutil contains advanced synchronization primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func With added in v0.0.12

func With(l sync.Locker, f func())

Runs f while holding the lock

func Without added in v0.0.12

func Without(l sync.Locker, f func())

Runs f while not holding the lock

Types

type Any

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

Any calls a group of functions in separate goroutines, and checks that at least one function call succeeded. The Wait method returns an error if (and only if) all calls to Go have failed. Compare to https://pkg.go.dev/golang.org/x/sync/errgroup.

A zero-value Any is valid. Any must not be copied after first use.

func AnyWithContext added in v0.0.2

func AnyWithContext(ctx context.Context) (*Any, context.Context)

AnyWithContext returns a new Any and an associated Context derived from ctx.

The derived Context is canceled the first time a function passed to Go succeeds (returns a nil error) or the first time Wait returns, whichever occurs first.

func (*Any) Go

func (a *Any) Go(f func() error)

Go calls the given function in a new goroutine.

The first call to return a nil error cancels the group; wait will then return nil.

func (*Any) Wait

func (a *Any) Wait() error

Wait blocks until all function calls from the Go method have returned, then returns nil if any of the calls succeeded. Otherwise, it returns the first non-nil error encountered.

type Barrier added in v0.0.5

type Barrier uint32

func (*Barrier) Signal added in v0.0.7

func (b *Barrier) Signal(finalize func()) (ready bool)

type BarrierChan added in v0.0.5

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

func NewBarrierChan added in v0.0.5

func NewBarrierChan(n uint32) BarrierChan

func (BarrierChan) Done added in v0.0.5

func (b BarrierChan) Done() <-chan struct{}

func (BarrierChan) Signal added in v0.0.8

func (b BarrierChan) Signal(finalize func()) (ready bool)

func (BarrierChan) SignalAndWait added in v0.0.5

func (b BarrierChan) SignalAndWait(finalize func())

type Breaker

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

A Breaker calls functions in separate goroutines, returning a nil error if one succeeds. Contrary to 'Any', calls to 'Wait" will block until either a function returns a nil error or all inflight functions have returned errors.

The zero-value Breaker is ready to use.

func BreakerWithContext added in v0.0.2

func BreakerWithContext(ctx context.Context) (*Breaker, context.Context)

BreakerWithContext returns a Breaker and an associated context derived from ctx.

The derived Context is canceled the first time a function passed to Go succeeds (returns a nil error) or the first time Wait returns, whichever occurs first.

func (*Breaker) Break

func (b *Breaker) Break()

Break renders each subsequent calls to 'Go' a nop. Aftr 'Break' returns, 'Wait' will block until all in-flight functions have returned.

func (*Breaker) Go

func (b *Breaker) Go(f func() error)

Go calls the function in a separate goroutine. If 'Break' has been previously called, this becomes a nop.

func (*Breaker) Wait

func (b *Breaker) Wait() error

Wait blocks until a function call succeeds, or until 'Break' has been called AND all in-flight functions have returned an error. In the latter case, it returns the first non-nil error encountered.

type Ctr

type Ctr uint32

Ctr is a 32-bit, lock-free counter

func (*Ctr) Decr

func (ctr *Ctr) Decr() uint32

Decr decrements the counter

func (*Ctr) Incr

func (ctr *Ctr) Incr() uint32

Incr increments the counter

func (*Ctr) Int added in v0.0.11

func (ctr *Ctr) Int() int

Int atomically loads the value as an untyped integer. This is useful for integer comparisons, e.g. with `len`.

func (*Ctr) Load added in v0.0.11

func (ctr *Ctr) Load() uint32

Load the value as a native uint32.

func (*Ctr) Uint added in v0.0.11

func (ctr *Ctr) Uint() uint

Uint atomically loads the value as an untyped uint.

type Ctr64 added in v0.0.11

type Ctr64 uint64

Ctr64 is a 64-bit, lock-free counter

func (*Ctr64) Decr added in v0.0.11

func (ctr *Ctr64) Decr() uint64

Decr decrements the counter

func (*Ctr64) Incr added in v0.0.11

func (ctr *Ctr64) Incr() uint64

Incr increments the counter

func (*Ctr64) Int added in v0.0.11

func (ctr *Ctr64) Int() int

Int atomically loads the value as an untyped integeger. This is useful for integer comparisons, e.g. with `len`.

func (*Ctr64) Load added in v0.0.11

func (ctr *Ctr64) Load() uint64

Load the value as a native uint64.

func (*Ctr64) Uint added in v0.0.11

func (ctr *Ctr64) Uint() uint

Uint atomically loads the value as an untyped uint.

type Flag

type Flag uint32

Flag is a lock-free boolean flag

func (*Flag) Bool

func (f *Flag) Bool() bool

Bool evaluates the flag's value

func (*Flag) Set

func (f *Flag) Set()

Set the flag's value to true

func (*Flag) Unset

func (f *Flag) Unset()

Unset the flag, making its value false

type FuncGroup

type FuncGroup sync.WaitGroup

FuncGroup calls a group of functions in separate goroutines and waits until they have all returned. Compare to https://pkg.go.dev/golang.org/x/sync/errgroup.

A zero-value FuncGroup is valid. FuncGroup must not be copied after first use.

func (*FuncGroup) Go

func (g *FuncGroup) Go(f func())

Go runs the supplied function in a goroutine

func (*FuncGroup) Wait

func (g *FuncGroup) Wait()

Wait for all goroutines to complete

type Join added in v0.0.4

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

Join calls a group of functions in separate goroutines and waits until they have all returned. The error returned by Join is a go.uber.org/multierr and is non-nil if any function returned a non-nil error.

Unlike pkg.go.dev/golang.org/x/sync/errgroup, Join does not return until the full set uf goroutines has finished

A zero-value Join is valid. Join must not be copied after first use.

func (*Join) Go added in v0.0.4

func (j *Join) Go(f func() error)

func (*Join) Wait added in v0.0.4

func (j *Join) Wait() error

Jump to

Keyboard shortcuts

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