future

package
v0.0.0-...-14fd01d Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package future provides types and methods for performing asynchronous actions that have return values that can be waited upon.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](ctx context.Context, funcs ...Func[T]) iter.Seq2[T, error]

All creates a Future for each provided Func, running each in its own goroutine. Results of each Future are exposed via an iter.Seq2 that can be ranged over. The first value of the iter.Seq2 is the return type of the Future, the second is any error that has occurred.

Types

type Func

type Func[T any] func(ctx context.Context) (T, error)

The Func type represents the action the future should take upon creation.

type Future

type Future[T any] struct {
	// contains filtered or unexported fields
}

The Future type is used to perform an asynchronous action and obtain its result at a later time.

func Do

func Do[T any](ctx context.Context, fn Func[T]) *Future[T]

Do returns a new Future that executes the given Func implementation. The function is invoked immediately within its own goroutine and its return value is made accessible via the Result method. The provided context is passed into the Func call for cancellation.

func (*Future[T]) Result

func (f *Future[T]) Result(ctx context.Context) (T, error)

Result returns the result of the Future. If the invoked Func is still in-progress, this method blocks until the Func has returned or the provided context is cancelled.

Jump to

Keyboard shortcuts

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