Documentation ¶
Overview ¶
Package thunk provides "thunks" (type T), which are wrappers around lazy or concurrent computations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Thunk ¶
type Thunk[A any] struct { // contains filtered or unexported fields }
A Thunk[A] wraps a value A which may not be available yet; goroutines may get the value by calling Force.
func Go ¶
Go is like Lazy, except that f() is invoked immediately in a separate goroutine. Calls to Force will block until f() returns.
func Lazy ¶
Lazy returns a new Thunk which, when forced, will return the value returned by f(). f() will be invoked lazily, i.e. not until Force() is called for the first time.
func Promise ¶
Promise returns a pair of a Thunk and a function fulfill to supply the value of the Thunk; calls to t.Force() will block until fulfill has been invoked, at which point they will return the value passed to fulfill. Fulfill must not be called more than once.