Promise
Represents the eventual outcome or failure of an eagerly executed computation.
Related Work and Inspiration
Generation
later(dt, a)
:: number → a → Promise a
of(a)
:: a -> Promise e a
reject(e)
:: * -> Promise *
Abbreviates Promise.reject
. Note that Promise.reject
rejects with any type including any Promise (unsettled, rejected or fulfilled)! Read what happens.
never()
:: () -> Promise ()
Creates a Promise which never settles.
Transformation
chainRej(onError)
:: (e -> Promise g b) -> Promise e a -> Promise (e | g) (a | b)
coalesce(onFailure, onSuccess, p)
:: (e -> b) -> (a -> b) -> Promise e a -> Promise e b
It's essentially Promise.then
and named coalesce in crocks Async.
mapRej(f)
:: (e -> c) -> Promise e b -> Promise c b
Side-Effects
bi_tap(onFailure, onSuccess, p)
:: (* -> *) -> (a -> *) -> Promise a -> Promise a
Like tap
but also with a failure side-effect function.
tap(fn, p)
:: (a -> *) -> Promise a -> Promise a
In this implementation an exception in the side-effect fn
rubs off to the Promise.
tapRegardless(fn, p)
:: (a -> *) -> Promise a -> Promise a
Execute a synchronous side effect. Aka forEach.
In this implementation an exception in the side-effect is ignored.
promise X ---------> X ---> \ - fn(X) -> Y
chainTap(fn, p)
:: (a -> Promise g *) -> Promise e a -> Promise (e|g) a
Execute an asynchronous (could be a side-effect) function and wait until it is settled.
Mostly like tap
except for the wait part.
Combination
ap(promisedFunc, promise)
:: Promise (a → b) → Promise a → Promise b
Parallel running version: Both Promises are treated equally in time, meaning if any fails the first failure is propagated to the result.
duplexRace(a, b)
:: Promise a → Promise a → Promise a
It's Promise.race
but only for two input promises.