Documentation ¶
Index ¶
- func Any[T any](g ctxErrgroup, v T, fn func(context.Context, T) error)
- func Group(ctx context.Context, options ...Option) ctxErrgroup
- func Map[K comparable, V any](g ctxErrgroup, vs map[K]V, fn func(context.Context, K, V) error)
- func MapContext[K comparable, V any](ctx context.Context, vs map[K]V, fn func(context.Context, K, V) error) error
- func MapReplace[K comparable, V any](g ctxErrgroup, vs map[K]V, fn func(context.Context, K, V) (V, error))
- 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
- func Slice[T any](g ctxErrgroup, vs []T, fn func(context.Context, T) error)
- func SliceContext[T any](ctx context.Context, vs []T, fn func(context.Context, T) error) error
- func SliceReplace[T any](g ctxErrgroup, vs []T, fn func(context.Context, T) (T, error))
- func SliceReplaceContext[T any](ctx context.Context, vs []T, fn func(context.Context, T) (T, error)) error
- func SliceReturn[T, O any](g ctxErrgroup, vs []T, fn func(context.Context, T) (O, error)) []O
- func SliceReturnContext[T, O any](ctx context.Context, vs []T, fn func(context.Context, T) (O, error)) ([]O, error)
- type Option
- type PanicError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
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 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 ¶
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 ¶
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 ¶
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 ¶
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
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.