Module

Effect.Promise

#promise

promise :: forall a. Deferred => ((a -> Effect Unit) -> (Error -> Effect Unit) -> Effect Unit) -> Promise a

Create a promise by supplying a function which takes a success callback and error callback as arguments, returning an Effect.

#then_

then_ :: forall a b. Deferred => (a -> Promise b) -> (Error -> Promise b) -> Promise a -> Promise b

Useful for when you need to transform an error and a resolved value into the same type.

#then'

then' :: forall a b. Deferred => (a -> Promise b) -> Promise a -> Promise b

Given a promise and a function which uses that promise's resolved value, create a new promise that resolves to the function's output.

#resolve

resolve :: forall a. a -> Promise a

Create a promise from a value.

#catch

catch :: forall a. Deferred => Promise a -> (Error -> Promise a) -> Promise a

Deals with any errors that may be thrown by the given promise.

#reject

reject :: forall b. Deferred => Error -> Promise b

Throw an error into a promise.

#race

race :: forall f a. Deferred => Foldable f => f (Promise a) -> Promise a

Note that while promise semantics say that race xs resolves to the first x in xs to resolve, race xs won't terminate until each promise is settled. In addition, if Array.fromFoldable xs is [], race xs will never settle.

#attempt

attempt :: forall a. Deferred => Promise a -> Promise (Either Error a)

Same as try.

#apathize

apathize :: forall a. Deferred => Promise a -> Promise Unit

#all

all :: forall f g a. Deferred => Foldable f => Unfoldable g => f (Promise a) -> Promise (g a)

Run all promises in the given Foldable, returning a new promise which either resolves to a collection of all the given promises' results, or rejects with the first promise to reject.

#delay

delay :: forall a. Deferred => Milliseconds -> a -> Promise a

Cause a delay in execution, then resolve with the given value.

#runPromise

runPromise :: forall a b. (a -> Effect b) -> (Error -> Effect b) -> (Deferred => Promise a) -> Effect Unit

Consume a promise. Note that this is the only standard way to safely discharge the Deferred constraints you are likely to have.

Re-exports from Effect.Promise.Unsafe

#Deferred

class Deferred 

A class for side-effecting promises which don't prematurely execute.

Modules