concurrency

package
v1.1.58 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Unlicense Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForAllAsync

func ForAllAsync(ctx context.Context, length int, cancelOnErr bool,
	routine func(context.Context, int, context.CancelFunc) error) error

ForAllAsync runs the provided funcction concurrently for every entry in the length provided in such a way that cancellation will short-circuit execution of the remaining functions. The routine is provided with a context that will be notified when short-circuiting occurs and a cancallation function that can be used to short-circuit the operation. If cancelOnErr is set to true, then routines will be not run after one returns an error

Types

type Asyncer added in v1.1.15

type Asyncer[T any] struct {
	// contains filtered or unexported fields
}

Asyncer allows for an operation to be done asynchronously with the control flow and then awaited at the caller's convenience

func NewAsyncer added in v1.1.15

func NewAsyncer[T any]() *Asyncer[T]

NewAsyncer creates a new Asyncer

func (*Asyncer[T]) Await added in v1.1.15

func (a *Asyncer[T]) Await() (T, error, bool)

Await blocks execution until something is received on either the errors channel or the results channel and then returns that value to the caller

func (*Asyncer[T]) Do added in v1.1.15

func (a *Asyncer[T]) Do(action func() (T, error))

Do runs the given function asynchronously, sending output and errors to the channels provided

func (*Asyncer[T]) Received added in v1.1.17

func (a *Asyncer[T]) Received() bool

Received returns a Boolean value showing whether or not a value has been received from the asynchronous function at the time it is called.

type Buffer

type Buffer[T any] struct {
	// contains filtered or unexported fields
}

Buffer allows for data to be requested in a quantity that is limited by a single parameter

func NewBuffer

func NewBuffer[T any](size int) *Buffer[T]

NewBuffer creates a new Buffer that allows concurrent operation on size elements of data

func (*Buffer[T]) Get

func (buf *Buffer[T]) Get() (*T, bool)

Get retrieves an item from the buffer. This function will block if the number of concurrent operations is at the value limited by size. Otherwise, an item will be removed from the data channel, if it exists, and returned. If data was in the channel then true will be returned as well. Otherwise, nil and false will be returned. The Release function should be called once operation on this data has ceased

func (*Buffer[T]) Load

func (buf *Buffer[T]) Load(data ...*T)

Load adds data to the buffer. This function may be called concurrently

func (*Buffer[T]) Release

func (buf *Buffer[T]) Release()

Release informs the buffer that work on one of the data items has completed and that another operation may begin.

func (*Buffer[T]) Size

func (buf *Buffer[T]) Size() int

Size returns the number of items of data that may be requested concurrently

Jump to

Keyboard shortcuts

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