rdv

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: 3 Imported by: 0

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 CtxApply

func CtxApply[T any](
	ctx context.Context,
	f func(context.Context) (T, error),
) func() (T, error)

CtxApply closes function f over the ctx argument to return a nulladic function.

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

func Go[T any](f func() (T, error)) Rdv[T]

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

func GoEg[T any](eg *errgroup.Group, f func() (T, error)) Rdv[T]

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

func (rv Rdv[T]) Receive() (T, error)

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

func (rv Rdv[T]) ReceiveWatch(ctx context.Context) (T, error)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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