effect/promise
Functions
pub fn from_promise(
box: Promise(a),
handler: fn(a) -> Effect(b, c),
) -> Effect(b, c)
Creates an effect from a promise, operates on the inner value through the handler.
let promise: Promise(inner)
use inner: inner <- from_promise(promise)
effect.succeed(inner) // Effect(inner, early)
pub fn from_promise_result(
box: Promise(Result(a, b)),
map_error: fn(b) -> c,
handler: fn(a) -> Effect(d, c),
) -> Effect(d, c)
Creates an effect from a promise that contains a result.
Maps the error of the result, operates on the inner value of the result through the handler.
let promise: Promise(Result(ok, err))
use ok: ok <- from_promise_result(promise, fn (previous_error) { new_error }) // map the error here
effect.succeed(ok) // Effect(ok, err)