struct Syn::Core::Future(T)

Overview

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)

Defined in:

core/future.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def 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


[View source]
def 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.


[View source]
def get : T #

Blocks the current fiber until the value is resolved.


[View source]
def get? : T | Nil #

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


[View source]
def set(value : T) : T #

Sets the value and wakes up pending fibers.

TODO raise if the future has already been resolved


[View source]