class Promise(T)
- Promise(T)
- Reference
- Object
Defined in:
promise.crConstructors
-
.new(&block : T -> Nil, String | Exception -> Nil -> _)
The
Promise(T).new(&block : (T -> Nil), (String | Exception -> Nil) -> _)
method Creates a new Promise with procs for how to resolve and how to reject the promise.
Class Method Summary
-
.all(promises : Array(Promise(T | Nil)))
The
Promise(T).all(promises : Array(Promise(T | Nil))
method returns a promise that resolves when all of the promises in the iterable argument have resolved, or rejects with the reason of the first passed promise that rejects. -
.execute(&block : -> T)
The
Promise(T).execute(&block : -> T)
method returns a Promise object that is resolved by the return value of the block. -
.race(promises : Array(Promise(T | Nil)))
The
Promise.race(promises : Array(Promise(T | Nil))
method returns aPromise
that is settled the same way as the first passed promise to settle. -
.reject(message : String)
The
Promise(T).reject(message : String)
method returns a Promise object that is rejected with the given reason. -
.reject(ex : Exception)
The
Promise(T).reject(ex : Exception)
method returns a Promise object that is rejected with the given reason. -
.resolve(value : T)
The
Promise(T).resolve(value : T)
method returns a Promise.then object that is resolved with the given value.
Instance Method Summary
-
#await
The
#await
method will block until the chain before the specified wait has finished it's operations, then returns the last value. -
#catch(&block : Exception -> _)
The
catch(&block : Exception -> _)
method specifies an operation to complete after the previous operation has been rejected. - #pending?
-
#rejected?
The
#rejected?
method will return true if thePromise
is rejected. -
#resolved?
The
#resolved?
method will return true if thePromise
is resolved. - #state
-
#then(&block : T -> _)
The
then(&block : T -> _)
method Specifies an operation to complete after the previous operation has been resolved.
Constructor Detail
The Promise(T).new(&block : (T -> Nil), (String | Exception -> Nil) -> _)
method Creates a new Promise with procs for how to resolve and how to reject the promise.
NOTE: Raised exceptions will also trigger a reject.
Class Method Detail
The Promise(T).all(promises : Array(Promise(T | Nil))
method returns a promise that
resolves when all of the promises in the iterable argument have resolved, or
rejects with the reason of the first passed promise that rejects.
The Promise(T).execute(&block : -> T)
method returns a Promise object that is resolved
by the return value of the block.
The Promise.race(promises : Array(Promise(T | Nil))
method returns a Promise
that
is settled the same way as the first passed promise to settle. It resolves
or rejects, whichever happens first.
The Promise(T).reject(message : String)
method returns a Promise object that is rejected
with the given reason.
Rejects with a string message
The Promise(T).reject(ex : Exception)
method returns a Promise object that is
rejected with the given reason.
Rejects with an exception.
The Promise(T).resolve(value : T)
method returns a Promise.then object that is
resolved with the given value.
Instance Method Detail
The #await
method will block until the chain before the specified wait has finished it's
operations, then returns the last value.
NOTE: This is typically used to prevent the application from terminating before the operations are complete, this may not be required if you have something else handling the process.
The catch(&block : Exception -> _)
method specifies an operation to complete after the previous operation has been
rejected.
NOTE: Using a catch will allow the continuation of the chain after the catch.
The then(&block : T -> _)
method Specifies an operation to complete after the previous operation has been resolved.