xsync

package
v0.0.0-...-f89cf20 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package errgroup provides synchronization, error propagation, and Context cancelation for groups of goroutines working on subtasks of a common task. This provide a concurrent call util and it's safe than golang.org/x/sync/errgroup ones

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyMutex

type AnyMutex struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewAnyMutex

func NewAnyMutex(any interface{}) *AnyMutex

func (*AnyMutex) Load

func (a *AnyMutex) Load() interface{}

func (*AnyMutex) Store

func (a *AnyMutex) Store(any interface{})

type AtomicBool

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

AtomicBool is an atomic Boolean.

func NewAtomicBool

func NewAtomicBool(initial bool) *AtomicBool

NewAtomicBool creates a AtomicBool.

func (*AtomicBool) CAS

func (b *AtomicBool) CAS(old, new bool) bool

CAS is an atomic compare-and-swap.

func (*AtomicBool) Load

func (b *AtomicBool) Load() bool

Load atomically loads the Boolean.

func (*AtomicBool) Store

func (b *AtomicBool) Store(new bool)

Store atomically stores the passed value.

func (*AtomicBool) Swap

func (b *AtomicBool) Swap(new bool) bool

Swap sets the given value and returns the previous value.

func (*AtomicBool) Toggle

func (b *AtomicBool) Toggle() bool

Toggle atomically negates the Boolean and returns the previous value.

type AtomicString

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

func NewAtomicString

func NewAtomicString(str string) *AtomicString

func (*AtomicString) Load

func (s *AtomicString) Load() string

func (*AtomicString) Store

func (s *AtomicString) Store(str string)

type Group

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

A Group is a collection of goroutines working on subtasks that are part of the same overall task.

A zero Group is valid and does not cancel on error.

func WithContext

func WithContext(ctx context.Context) (*Group, context.Context)

WithContext returns a new Group and an associated Context derived from ctx.

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

func (*Group) Go

func (g *Group) Go(f func() error)

Go calls the given function in a new goroutine.

The first call to return a non-nil error cancels the group; its error will be returned by Wait.

func (*Group) Wait

func (g *Group) Wait() error

Wait blocks until all function calls from the Go method have returned, then returns the first non-nil error (if any) from them.

type Weighted

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

Weighted provides a way to bound concurrent access to a resource. The callers can request access with a given weight.

func NewWeighted

func NewWeighted(n int64) *Weighted

NewWeighted creates a new weighted semaphore with the given maximum combined weight for concurrent access.

func (*Weighted) Acquire

func (s *Weighted) Acquire(ctx context.Context, n int64) error

Acquire acquires the semaphore with a weight of n, blocking until resources are available or ctx is done. On success, returns nil. On failure, returns ctx.Err() and leaves the semaphore unchanged.

If ctx is already done, Acquire may still succeed without blocking.

func (*Weighted) Release

func (s *Weighted) Release(n int64)

Release releases the semaphore with a weight of n.

func (*Weighted) TryAcquire

func (s *Weighted) TryAcquire(n int64) bool

TryAcquire acquires the semaphore with a weight of n without blocking. On success, returns true. On failure, returns false and leaves the semaphore unchanged.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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