class Syn::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:

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/failed


[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.

EXPERIMENTAL The timeout feature is experimental.


[View source]
def get : T #

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


[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/failed


[View source]