futures

package
v0.0.0-...-3b62d95 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitAllSlice

func WaitAllSlice[T any](futures []Future[T]) ([]T, error)

func WaitAllSliceCtx

func WaitAllSliceCtx[T any](ctx context.Context, futures []Future[T]) ([]T, error)

Types

type Future

type Future[T any] interface {
	// GoSync executes the provided function in the current Goroutine and
	// resolves the future with the return result.
	GoSync(func() (T, error))
	// GoAsync is the same as GoSync, but it runs the function in a new
	// goroutine and doesn't block the caller.
	GoAsync(func() (T, error))
	// Resolve resolves the future immediately with result.
	Resolve(result T)
	// Reject rejects the future immediately with an error.
	Reject(err error)
	// ResolveOrReject combines Resolve and Reject into one method for
	// convenience.
	ResolveOrReject(result T, err error)
	// Wait waits for the future to resolve and returns the tuple of
	// result/error.
	Wait() (result T, err error)
}

Future is the interface for a Future. It behaves similarly to a Promise or Future in other programming languages.

func New

func New[T any]() Future[T]

Jump to

Keyboard shortcuts

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