rx/future
Types
A single asynchronous result that may resolve at a later time.
A Future is deliberately execution-agnostic. Its producer may use a BEAM
process, timer, socket, database client, FFI callback, or any other mechanism.
The returned cancellation function should stop underlying work when possible.
Producers must resolve at most once. When a Future is used through the reactive flow operators, duplicate or late completions are ignored by the owning flow state machine.
pub opaque type Future(value, error)
Values
pub fn await(
future: Future(value, error),
continue: fn(Result(value, error)) -> Nil,
) -> fn() -> Nil
use-friendly spelling for registering a later continuation.
Example:
use result <- future.await(fetch_user())
case result {
Ok(user) -> use_user(user)
Error(reason) -> report(reason)
}
This does not block a BEAM scheduler or the rx Runtime actor. It registers the continuation and returns the Future’s physical cancellation callback.
pub fn from_effect(
effect_: effect.Effect(value, error),
) -> Future(value, error)
pub fn new(
start: fn(fn(Result(value, error)) -> Nil) -> fn() -> Nil,
) -> Future(value, error)
pub fn run(
future: Future(value, error),
resolve: fn(Result(value, error)) -> Nil,
) -> fn() -> Nil
pub fn to_effect(
future: Future(value, error),
) -> effect.Effect(value, error)