Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotReady = errors.New("future not ready")
ErrNotReady is returned when a future is not complete.
Functions ¶
This section is empty.
Types ¶
type Future ¶
Future represents a read-only view of the result of an asynchronous operation.
Construct a future either using NewAsync or from a Promise with Promise.Future.
func DoAsync ¶
DoAsync schedules an asynchronous operation on the Group and returns a Future to retrieve the eventual result.
func NewAsync ¶
NewAsync runs fn asynchronously, immediately returning a Future that can be used to retrieve the eventual result. This allows separating computation from evaluating the result.
func (*Future[R]) Await ¶
Await returns the cached result or blocks until a result is available or the context is canceled.
func (*Future[_]) Done ¶
func (f *Future[_]) Done() <-chan struct{}
Done returns a channel that is closed when the future is complete. It enables the use of future values in select statements.
func (*Future[R]) Try ¶
Try returns the cached result when ready, ErrNotReady otherwise.
type Group ¶
type Group interface {
Go(fn func() error)
}
A Group is a collection of asynchronous operations working on the same task.
type Promise ¶
type Promise[R any] struct { // contains filtered or unexported fields }
Promise defines the common operations for resolving a Future to its final value.
An empty value is valid and must not be copied after creation. One of the resolving operations may be called once from any goroutine, all subsequent calls will panic.