futures

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Future

type Future[R any] interface {
	Wait() R
}

Future represents a computation that will produce a result of type R in the future. The result can be retrieved by calling the Wait method, which blocks until the computation is complete.

func RaceAll

func RaceAll[R any](futures ...Future[R]) Future[R]

RaceAll takes multiple Future instances and returns a new Future that resolves to the result of the first Future to complete. The remaining Future computations are not canceled and will continue to execute in the background.

func Start

func Start[R any](ctx context.Context, fn func(ctx context.Context) R) Future[R]

Start begins a computation that runs the provided function fn in a separate goroutine. The computation's result of type R can be retrieved by calling the Wait method on the returned Future. The provided ctx is passed to the function fn to support context-aware operations.

func Value

func Value[R any](value R) Future[R]

Value creates a Future that immediately resolves to the provided value. The computation runs in a separate goroutine and can be awaited using the Wait method.

func WaitAll

func WaitAll[R any](futures ...Future[R]) Future[[]R]

WaitAll takes multiple Future instances and returns a new Future that resolves to a slice of results once all the provided Future instances have completed. The results are returned in the same order as the input Future instances.

func WaitMap added in v0.4.0

func WaitMap[K comparable, R any](m map[K]Future[R]) Future[map[K]R]

WaitMap takes a map of Future instances and returns a new Future that resolves to a map containing the results of all the provided Future instances. The keys in the resulting map correspond to the keys in the input map, and the values are the results of the respective Future computations.

Jump to

Keyboard shortcuts

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