Module

Effect.Promise

Package
purescript-promises
Repository
thimoteus/purescript-promises

#promise Source

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_ Source

then_ :: forall b a. 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' Source

then' :: forall b a. 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 Source

resolve :: forall a. a -> Promise a

Create a promise from a value.

#catch Source

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

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

#reject Source

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

Throw an error into a promise.

#race Source

race :: forall a f. 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.

#all Source

all :: forall a g f. 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 Source

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

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

#runPromise Source

runPromise :: forall b a. (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 Source

class Deferred 

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