await

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any[T any](g ctxErrgroup, v T, fn func(context.Context, T) error)

Any takes any input, and asyncronously calls `fn`. If any error is encoutered, the context is canceled and execution stops. n.b. this method does not provide any thread-safe guarantees on T.

func Group

func Group(ctx context.Context, options ...Option) ctxErrgroup

Group returns a new wrapped errgroup.Group, with the given context.

func Map

func Map[K comparable, V any](g ctxErrgroup, vs map[K]V, fn func(context.Context, K, V) error)

Map takes a map of any input, and asyncronously calls `fn` over each K/V pair. If any error is encoutered, the context is cancelled and execution stops.

func MapContext

func MapContext[K comparable, V any](ctx context.Context, vs map[K]V, fn func(context.Context, K, V) error) error

MapContext is a convenience method which calls Map, but constructs the Group for you. This is useful if you do not require chaining the group with any other types.

func MapReplace

func MapReplace[K comparable, V any](g ctxErrgroup, vs map[K]V, fn func(context.Context, K, V) (V, error))

MapReplace takes a map of any input, and asyncronously calls `fn` over every item, replacing the value in the map with the one returned by `fn`. If any error is encoutered, the context is cancelled and execution stops. This function is useful if you wish to modify the values of the map as a result of an asynchronous call, as all operations are wrapped in a mutex for safety.

func MapReturn

func MapReturn[K comparable, V, VO any](g ctxErrgroup, vs map[K]V, fn func(context.Context, K, V) (K, VO, error)) map[K]VO

MapReturn takes a map of any input, and asyncronously calls `fn` over every item, returning a key, value pair or error. If If any error is encoutered, the context is cancelled and execution stops. This function is useful if you wish to modify the values of the slice as a result of an asynchronous call, without changing the underlying pointer value which could result in data races. The returned map should not be accessed until the the group's Wait has finished.

func Slice

func Slice[T any](g ctxErrgroup, vs []T, fn func(context.Context, T) error)

Slice takes a slice of any input, and asyncronously calls `fn` over every item. If any error is encoutered, the context is cancelled and execution stops.

func SliceContext

func SliceContext[T any](ctx context.Context, vs []T, fn func(context.Context, T) error) error

SliceContext is a convenience method which calls Slice, but constructs the Group for you. This is useful if you do not require chaining the group with any other types.

func SliceReplace

func SliceReplace[T any](g ctxErrgroup, vs []T, fn func(context.Context, T) (T, error))

SliceReplace takes a slice of any input, and asyncronously calls `fn` over every item, replacing the value in the slice with the one returned by `fn`. If any error is encoutered, the context is cancelled and execution stops. This function is useful if you wish to modify the values of the slice as a result of an asynchronous call, without changing the underlying pointer value which could result in data races.

func SliceReplaceContext

func SliceReplaceContext[T any](ctx context.Context, vs []T, fn func(context.Context, T) (T, error)) error

SliceReplaceContext is a convenience method which calls SliceReplace, but constructs the Group for you. This is useful if you do not require chaining the group with any other types.

func SliceReturn

func SliceReturn[T, O any](g ctxErrgroup, vs []T, fn func(context.Context, T) (O, error)) []O

SliceReturn takes a slice of any input, and asyncronously calls `fn` over every item, collecting the return values of each execution to be returned as a new slice when finished. If any error is encoutered, the context is cancelled and execution stops. The returned slice should not be accessed until the the group's Wait has finished.

func SliceReturnContext

func SliceReturnContext[T, O any](ctx context.Context, vs []T, fn func(context.Context, T) (O, error)) ([]O, error)

SliceReplaceContext is a convenience method which calls SliceReplace, but constructs the Group for you. This is useful if you do not require chaining the group with any other types.

Types

type Option

type Option func(ctxErrgroup)

Option defines a function which can be passed to Group. See the available options:

  • WithLimit

func WithLimit

func WithLimit(limit int) Option

WithLimit sets the maximum amount of goroutines running in the errgroup at any point in time.

type PanicError

type PanicError struct {
	Panic any
}

PanicError wraps a recovered panic and is returned if a goroutine panics.

func (PanicError) Error

func (pe PanicError) Error() string

Error conforms to the error interface.

Jump to

Keyboard shortcuts

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