amber/web/promise
Types
pub type PromiseWithResolvers(a) {
PromiseWithResolvers(
promise: Promise(a),
resolve: fn(a) -> Nil,
reject: fn(Dynamic) -> Nil,
)
}
Constructors
-
PromiseWithResolvers( promise: Promise(a), resolve: fn(a) -> Nil, reject: fn(Dynamic) -> Nil, )
Functions
pub fn all(values: List(Promise(a))) -> Promise(List(a))
Creates a Promise that is resolved with a list of results when all of the provided Promises resolve, or rejected when any Promise is rejected.
pub fn all_settled(
values: List(Promise(a)),
) -> Promise(List(PromiseSettledResult(a)))
Creates a Promise that is resolved with a list of PromiseSettledResult
s
when all of the provided Promises resolve or reject.
pub fn any(values: List(Promise(a))) -> Promise(a)
Returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing a list of rejection reasons if all of the given promises are rejected.
pub fn catch(
promise: Promise(a),
onrejected: fn(b) -> Nil,
) -> Promise(a)
Attaches a callback for the rejection of the Promise.
pub fn finally(
promise: Promise(a),
onfinally: fn() -> Nil,
) -> Promise(a)
Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.
pub fn new(
executor: fn(fn(a) -> Nil, fn(b) -> Nil) -> Nil,
) -> Promise(a)
Creates a new Promise. The executor callback is passed two arguments: a resolve callback used to resolve the promise with a value, and a reject callback used to reject the promise with a provided reason or error.
pub fn race(values: List(Promise(a))) -> Promise(a)
Creates a Promise that is resolved or rejected when any of the provided Promises are resolved or rejected.
pub fn reject(reason: a) -> Promise(b)
Creates a new rejected promise for the provided reason.
pub fn resolve(value: a) -> Promise(a)
Creates a new resolved promise for the provided value.
pub fn then(
promise: Promise(a),
onfulfilled: fn(a) -> b,
) -> Promise(b)
Attaches a callback for the resolution of the Promise.
pub fn with_resolvers() -> PromiseWithResolvers(a)
Creates a new Promise and returns it in a PromiseWithResolvers
record,
along with its resolve and reject functions.