Documentation ¶
Index ¶
- func GoEg[T any](w EgWaiter, f func(context.Context) (T, error), pResult *T)
- func GoWg[T any](w WgWaiter, f func(context.Context) (T, error), pResult *ResultWithError[T])
- func RunConcurrent2Eg[T1, T2 any](ctx context.Context, f1 func(context.Context) (T1, error), ...) (util.Tuple2[T1, T2], error)
- func RunConcurrent2Wg[T1, T2 any](ctx context.Context, f1 func(context.Context) (T1, error), ...) (util.Tuple2[ResultWithError[T1], ResultWithError[T2]], error)
- func RunConcurrentsEg[T any](ctx context.Context, funcs ...func(context.Context) (T, error)) ([]T, error)
- func RunInBackground[T any](ctx context.Context, f func(context.Context) (T, error), ...) (T, error)
- type EgWaiter
- type Promise
- func Async[T any](ctx context.Context, f func(context.Context) (T, error)) Promise[T]
- func Async2Eg[T1 any, T2 any](ctx context.Context, f1 func(ctx context.Context) (T1, error), ...) Promise[util.Tuple2[T1, T2]]
- func Async2Wg[T1 any, T2 any](ctx context.Context, f1 func(ctx context.Context) (T1, error), ...) Promise[util.Tuple2[ResultWithError[T1], ResultWithError[T2]]]
- func AsyncsEg[T any](ctx context.Context, funcs ...func(ctx context.Context) (T, error)) Promise[[]T]
- func AsyncsWg[T any](ctx context.Context, funcs ...func(ctx context.Context) (T, error)) Promise[[]ResultWithError[T]]
- type ResultWithError
- type SingleWaiter
- type Unit
- type WgWaiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoEg ¶
GoEg launches f as a saparate goroutine and puts its non-error result in the struct pointed to by pResult. Before using the result, a caller must wait on the Waiter passed into this function. If f panics, the panic value is converted to an error and set in the result.
func GoWg ¶
GoWg launches f as a saparate goroutine and puts its result in the struct pointed to by pResult. Before using the result, a caller must wait on the Waiter passed into this function. If f panics, the panic value is converted to an error and set in the result.
func RunConcurrent2Eg ¶
func RunConcurrent2Eg[T1, T2 any]( ctx context.Context, f1 func(context.Context) (T1, error), f2 func(context.Context) (T2, error), ) (util.Tuple2[T1, T2], error)
RunConcurrent2Eg 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.
func RunConcurrent2Wg ¶
func RunConcurrent2Wg[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)
RunConcurrent2Wg 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.
func RunConcurrentsEg ¶
func RunConcurrentsEg[T any]( ctx context.Context, funcs ...func(context.Context) (T, error), ) ([]T, error)
RunConcurrentsEg 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.
func RunInBackground ¶
func RunInBackground[T any]( ctx context.Context, f func(context.Context) (T, error), errorHandler func(error), ) (T, error)
RunInBackground runs a function in the background as a goroutine. This function returns early if the context ctx is cancelled or times-out. In all cases, errorHandler is executed if f returns an error, even if f completes after the context ctx is cancelled.
Types ¶
type EgWaiter ¶
type EgWaiter struct { P preWaiter // embedded structs not supported by go2go Eg *errgroup.Group EgCtx context.Context }
EgWaiter supports waiting on the completion of a group of goroutines associated with an errgroup.Group.
func MakeEgWaiter ¶
MakeEgWaiter constructs an EgWaiter.
func (EgWaiter) Wait ¶
Wait waits on both the WaitCh channel field in the receiver and the Done() channel for the Ctx context field in the receiver. If Ctx.Done() happens first then this method returns a DeadlineExceeded or a Canceled error. Otherwise, it returns the error received in WaitCh. This function may be called multiple times and always returns the same results.
type Promise ¶
Promise supports awaiting on and receiving the result of an asynchronous computation.
func Async2Eg ¶
func Async2Eg[T1 any, T2 any]( ctx context.Context, f1 func(ctx context.Context) (T1, error), f2 func(ctx context.Context) (T2, error), ) Promise[util.Tuple2[T1, T2]]
Async2Eg returns a Promise for the concurrent execution of the functions f1 and f2 in an errgroup.Group. The Promise completes when the error group Wait method returns.
func Async2Wg ¶
func Async2Wg[T1 any, T2 any]( ctx context.Context, f1 func(ctx context.Context) (T1, error), f2 func(ctx context.Context) (T2, error), ) Promise[util.Tuple2[ResultWithError[T1], ResultWithError[T2]]]
Async2Wg returns a Promise for the concurrent execution of the functions f1 and f2 in a sync.WaitGroup. The Promise completes when the wait group Wait method returns.
func AsyncsEg ¶
func AsyncsEg[T any]( ctx context.Context, funcs ...func(ctx context.Context) (T, error), ) Promise[[]T]
AsyncsEg returns a Promise for the concurrent execution of the functions funcs in an errgroup.Group. The Promise completes when the error group Wait method returns.
func AsyncsWg ¶
func AsyncsWg[T any]( ctx context.Context, funcs ...func(ctx context.Context) (T, error), ) Promise[[]ResultWithError[T]]
AsyncsWg returns a Promise for the concurrent execution of the functions funcs in a sync.WaitGroup. The Promise completes when the wait group Wait method returns.
type ResultWithError ¶
ResultWithError encapsulates a normal result value and an error.
func RunConcurrentsWg ¶
func RunConcurrentsWg[T any]( ctx context.Context, funcs ...func(context.Context) (T, error), ) ([]ResultWithError[T], error)
RunConcurrentsWg 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.
type SingleWaiter ¶
type SingleWaiter struct { P preWaiter // embedded structs not supported by go2go ComplCh chan Unit }
SingleWaiter supports waiting on the completion of a single goroutine.
func Go ¶
func Go[T any]( ctx context.Context, f func(context.Context) (T, error), pResult *ResultWithError[T], ) SingleWaiter
Go launches f as a saparate goroutine and puts its result in the struct pointed to by pResult. Before using the result, a caller must wait on the Waiter returned by this function. If f panics, the panic value is converted to an error and set in the result.
func MakeSingleWaiter ¶
func MakeSingleWaiter(ctx context.Context) SingleWaiter
MakeSingleWaiter constructs a SingleWaiter.
func (SingleWaiter) Wait ¶
func (w SingleWaiter) Wait() error
Wait waits on both the WaitCh channel field in the receiver and the Done() channel for the Ctx context field in the receiver. If Ctx.Done() happens first then this method returns a DeadlineExceeded or a Canceled error. Otherwise, it returns the error received in WaitCh. This function may be called multiple times and always returns the same results.
type WgWaiter ¶
WgWaiter supports waiting on the completion of a group of goroutines associated with a sync.WaitGroup.
func MakeWgWaiter ¶
MakeWgWaiter constructs a WgWaiter.
func (WgWaiter) Wait ¶
Wait waits on both the WaitCh channel field in the receiver and the Done() channel for the Ctx context field in the receiver. If Ctx.Done() happens first then this method returns a DeadlineExceeded or a Canceled error. Otherwise, it returns the error received in WaitCh. This function may be called multiple times and always returns the same results.