class

Syn::Future(T)

Inherits Reference / Object

An object that will eventually hold a value.

Can be used to ask an Agent to compute a value asynchronously, while the current fiber continues to do other things, yet be able to retrieve or wait until the value is available.

TODO: report a failure with an optional exception

Constructors

Instance methods

fail(error : Exception | String | Nil = nil) : Nil

Report a failure when trying to resolve the future. Wakes up pending fibers.

TODO: raise if the future has already been resolved/failed

Source
get(timeout : Time::Span) : T | Nil

Blocks the current fiber until the value is resolved or timeout is reached, in which case it returns nil.

Source
get

Blocks the current fiber until the value is resolved. Raises an exception if the future has failed.

Source
get?

Returns the value if it was resolved. Returns nil otherwise without blocking. Raises an exception if the future has failed.

Source
set(value : T) : T

Sets the value and wakes up pending fibers.

TODO: raise if the future has already been resolved/failed

Source