Documentation
¶
Overview ¶
Package concurrentloop provides a function to call a function concurrently powered by generics, channels, and goroutines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecuteCh ¶ added in v1.1.1
func ExecuteCh[T any](ctx context.Context, fns []ExecuteFunc[T]) chan ResultCh[T]
ExecuteCh calls the `fns` concurrently.
NOTE: It's the caller's responsibility to close the channel.
func MapCh ¶ added in v1.1.1
func MapCh[T any, Result any](ctx context.Context, sl []T, f MapFunc[T, Result]) chan ResultCh[Result]
MapCh calls the `Func` concurrently on each element of `sl`, and returns a channel that receives the results. The results are returned as an `ResultCh` struct, which contains the output value and an error value if the function call failed.
NOTE: It's the caller's responsibility to close the channel.
Types ¶
type Errors ¶ added in v1.1.0
type Errors []error
Errors is a slice of errors.
func Execute ¶ added in v1.1.1
func Execute[T any](ctx context.Context, fns []ExecuteFunc[T]) ([]T, Errors)
Execute calls the `fns` concurrently, and returns the results and any errors that occurred. The function blocks until all executions have completed.
NOTE: Order is may preserved.
type ExecuteFunc ¶ added in v1.1.1
ExecuteFunc is the type of the function that will be executed concurrently for each element in a slice of type `T`. The function takes a `context.Context` and a value of type `T`, and returns a value of type `Result` and an error value.