Documentation
¶
Overview ¶
Package rdv supports the safe and convenient execution of asynchronous computations with goroutines and provides facilities for the safe retrieval of the computation results. It provides safety in the sense that panics in asynchronous computations are transformed into error results and its methods and functions prevent resource leaks, race conditions, and deadlocks for the channels used to pass data between the parent and child goroutines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CtxApplyWatch ¶
func CtxApplyWatch[T any]( ctx context.Context, f func(context.Context) (T, error), ) func() (T, error)
CtxApplyWatch closes function f over the ctx argument to return a nulladic function and watches ctx for deadline expiration or cancellation. If ctx is not cancelled or times-out, the resulting function returns the results of f. Otherwise, the resulting function returns early with a TimeoutError or CancellationError.
Types ¶
type Rdv ¶
type Rdv[T any] struct { // contains filtered or unexported fields }
Rdv encapsulates a channel used for a function launched as a goroutine to rendezvous with the user of the function's results.
func Go ¶
Go launches f as an asynchronous computation in a goroutine and returns an Rdv instance to be used to retrieve the results of the computation.
func GoEg ¶
GoEg launches f as an asynchronous computation in a goroutine associated with the errgroup.Group eg and returns an Rdv instance to be used to retrieve the results of the computation.
func (Rdv[T]) Receive ¶
Receive waits on the receiver and returns the results of the asynchronous computation for which the receiver was created (see Go and GoEg). For this method and ReceiveWatch, altogether at most one invocation is allowed for a given receiver.
func (Rdv[T]) ReceiveWatch ¶
ReceiveWatch waits on the receiver and watches the context ctx for cancellation or timeout. If ctx is not cancelled or times-out, this function returns the results of the asynchronous computation for which the receiver was created (see Go and GoEg). Otherwise, this function returns early with a TimeoutError or CancellationError. For this method and Receive, altogether at most one invocation is allowed for a given receiver.