Constructor
new Promise(executor)
Promise stub object (not fulfill specification, only for internal use)
Class not defined if Promise class already defined in root context
The Promise object is used for deferred and asynchronous computations. A Promise is in one of the three states:
The Promise object is used for deferred and asynchronous computations. A Promise is in one of the three states:
- pending: initial state, not fulfilled or rejected.
- fulfilled: successful operation
- rejected: failed operation.
Parameters:
| Name | Type | Description |
|---|---|---|
executor |
function | Function object with two arguments resolve and reject. The first argument fulfills the promise, the second argument rejects it. We can call these functions, once our operation is completed. |
- Source:
Methods
-
(static) all(promises) → {Promise}
-
The Promise.all(iterable) method returns a promise that resolves when all of the promises in the iterable argument have resolved.
The result is passed as an array of values from all the promises. If something passed in the iterable array is not a promise, it's converted to one by Promise.resolve. If any of the passed in promises rejects, the all Promise immediately rejects with the value of the promise that rejected, discarding all the other promises whether or not they have resolved.Parameters:
Name Type Description promisesKeyUsages Array with promises. - Source:
Returns:
- Type
- Promise
-
catch(onRejected) → {Promise}
-
The catch() method returns a Promise and deals with rejected cases only. It behaves the same as calling Promise.prototype.then(undefined, onRejected).
Parameters:
Name Type Description onRejectedfunction A Function called when the Promise is rejected. This function has one argument, the rejection reason. - Source:
Returns:
- Type
- Promise
-
then(onFulfilled, onRejected) → {Promise}
-
The then() method returns a Promise. It takes two arguments, both are callback functions for the success and failure cases of the Promise.
Parameters:
Name Type Description onFulfilledfunction A Function called when the Promise is fulfilled. This function has one argument, the fulfillment value. onRejectedfunction A Function called when the Promise is rejected. This function has one argument, the rejection reason. - Source:
Returns:
- Type
- Promise