Documentation
¶
Index ¶
- type Future
- func After[T any](fs ...Future[T]) Future[struct{}]
- func Err[T any](err error) Future[T]
- func Join[T any](fs ...Future[T]) Future[[]T]
- func Map[T any, U any](f Future[T], fn func(Result[T]) Result[U]) Future[U]
- func MapOk[T any, U any](f Future[T], fn func(T) U) Future[U]
- func MapOkToAny[T any](f Future[T]) Future[any]
- func MapOkValue[T any, U any](f Future[T], v U) Future[U]
- func New[T any](poll func() (Result[T], bool)) Future[T]
- func Ok[T any](v T) Future[T]
- func Then[T any, U any](f Future[T], fn func(Result[T]) Future[U]) Future[U]
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Future ¶
type Future[T any] struct { // contains filtered or unexported fields }
Future represents a result that will be available at some point in the future. It is very similar to Rust's Future trait.
func After ¶
After returns a single future that resolves after all of the given futures. If any future errors, the returned future immediately resolves to an error. This is very similar to Join except that the resolved value will be empty (making it more efficient if you don't need the values from the joined futures).
func Join ¶
Join combines the values from multiple futures into a single future that resolves to []T. If any future errors, the returned future immediately resolves to an error.
func MapOkToAny ¶
MapOk converts a future's value to an `any` type.
func MapOkValue ¶
MapOk converts a future's value to a value of a different type.
func New ¶
New constructs a new future from a poll function. When the future's value is ready, poll should return the value and true. Otherwise, poll should return a zero value and false.
func Then ¶
Then invokes f when the future is resolved and returns a future that resolves when f's return value is resolved.