rdvext

package
v0.5.22 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Simple extensions to rdv package to support running groups of functions concurrently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Go2

func Go2[T1 any, T2 any](
	ctx context.Context,
	f1 func(ctx context.Context) (T1, error),
	f2 func(ctx context.Context) (T2, error),
) rdv.Rdv[util.Tuple2[ResultWithError[T1], ResultWithError[T2]]]

Go2 returns an rdv.Rdv for the concurrent execution of the functions f1 and f2. The rdv.Rdv encapsulates a tuple containing the results of the function executions once all functions complete normaly, with an error, or with a panic. Panics in function executions are converted to errors. In case of a context timeout or cancellation, the rdv.Rdv completes early with a TimeoutError or CancellationError.

func Go2Eg

func Go2Eg[T1 any, T2 any](
	ctx context.Context,
	f1 func(ctx context.Context) (T1, error),
	f2 func(ctx context.Context) (T2, error),
) rdv.Rdv[util.Tuple2[T1, T2]]

Go2Eg returns an rdv.Rdv for the concurrent execution of the functions f1 and f2 in an errgroup.Group. The rdv.Rdv encapsulates a tuple containing the non-error results of the function executions if all functions complete normaly. If any of the functions returns an error or panics, this function returns early, with the first error encountered. Panics in function executions are converted to errors. In case of a context timeout or cancellation, the rdv.Rdv completes early with a TimeoutError or CancellationError.

func GoSlice

func GoSlice[T any](
	ctx context.Context,
	funcs ...func(ctx context.Context) (T, error),
) rdv.Rdv[[]ResultWithError[T]]

GoSlice returns an rdv.Rdv for the concurrent execution of the functions funcs in a sync.WaitGroup. The rdv.Rdv encapsulates a slice containing the results of the function executions once all functions complete normaly, with an error, or with a panic. Panics in function executions are converted to errors. In case of a context timeout or cancellation, the rdv.Rdv completes early with a TimeoutError or CancellationError.

func GoSliceEg

func GoSliceEg[T any](
	ctx context.Context,
	funcs ...func(ctx context.Context) (T, error),
) rdv.Rdv[[]T]

GoSliceEg returns an rdv.Rdv for the concurrent execution of the functions funcs in an errgroup.Group. The rdv.Rdv encapsulates a slice containing the non-error results of the function executions if all functions complete normaly. If any of the functions returns an error or panics, this function returns early, with the first error encountered. Panics in function executions are converted to errors. In case of a context timeout or cancellation, the rdv.Rdv completes early with a TimeoutError or CancellationError.

func Run2

func Run2[T1, T2 any](
	ctx context.Context,
	f1 func(context.Context) (T1, error),
	f2 func(context.Context) (T2, error),
) (util.Tuple2[ResultWithError[T1], ResultWithError[T2]], error)

Run2 runs funcs concurrently and returns a tuple containing the results of the function executions once all functions complete normaly, with an error, or with a panic. Panics in function executions are converted to errors. In case of a context timeout or cancellation, this functionn returns early with a TimeoutError or CancellationError for each of the funcs that had not aready returned. If there are any errors, the returned error is the one associated with the first function in the list of aguments that has an error response (not necessarily the first function to return an error).

func Run2Eg

func Run2Eg[T1, T2 any](
	ctx context.Context,
	f1 func(context.Context) (T1, error),
	f2 func(context.Context) (T2, error),
) (util.Tuple2[T1, T2], error)

Run2Eg runs funcs concurrently and returns a tuple containing the non-error results of the function executions if all functions complete normaly. If any of the functions returns an error or panics, this function returns early, with the first error encountered. Panics in function executions are converted to errors. In case of a context timeout or cancellation, this functionn returns early with a TimeoutError or CancellationError.

func RunSliceEg

func RunSliceEg[T any](
	ctx context.Context,
	funcs ...func(context.Context) (T, error),
) ([]T, error)

RunSliceEg runs funcs concurrently and returns a slice containing the non-error results of the function executions if all functions complete normaly. If any of the functions returns an error or panics, this function returns early, with the first error encountered. Panics in function executions are converted to errors. In case of a context timeout or cancellation, this functionn returns early with a TimeoutError or CancellationError.

Types

type ResultWithError

type ResultWithError[T any] struct {
	Value T
	Error error
}

ResultWithError encapsulates a normal result value and an error.

func RunSlice

func RunSlice[T any](
	ctx context.Context,
	funcs ...func(context.Context) (T, error),
) ([]ResultWithError[T], error)

RunSlice runs funcs concurrently and returns a slice containing the results of the function executions once all functions complete normaly, with an error, or with a panic. Panics in function executions are converted to errors. In case of a context timeout or cancellation, this functionn returns early with a TimeoutError or CancellationError for each of the funcs that had not aready returned. If there are any errors, the returned error is the one associated with the first function in the list of aguments that has an error response (not necessarily the first function to return an error).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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