concurrency

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 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 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