Promise
A promise holds a value to be resolved in the future.
This class is a “polyfill” for the standard Promise
class; it is only used when the running JavaScript environment
doesn’t support or include a Promise
class
on its own.
Parameters
resolver
(Type: function) (optional)
Function that takes two arguments: the first is a function to call when resolving the promise, and the second is a function to call when rejecting the promise.
Methods
- all
Wait for all these promises to complete. - race
Creates a promise that resolves or is rejected when one of those promises resolves or is rejected. - reject
Returns a promise that is rejected. - resolve
Returns a promise that resolves.
Wait for all these promises to complete. One failed => this fails too.
Parameters
all
(Type: Array.<Promise>)
An array of promises.
Return Value
A promise that is resolved when all promises have resolved. (Type: Promise)
### (static) Promise.race(all)
Creates a promise that resolves or is rejected when one of those promises resolves or is rejected.
Parameters
all
(Type: Array.<Promise>)
An array of promises.
Return Value
A promise that resolves or is rejected according to the first promise that resolves or is rejected. It will receive the value associated with that promise. (Type: Promise)
### (static) Promise.reject(reason)
Returns a promise that is rejected.
Parameters
reason
(Type: Object)
The value associated with the promise.
Return Value
A promise that is rejected and takes the given value as its argument. (Type: Promise)
### (static) Promise.resolve(value)
Returns a promise that resolves.
Parameters
value
(Type: Object)
The value associated with the promise.
Return Value
A promise that resolves and takes the given value as its argument. (Type: Promise)