Promise
Overview
The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value For more information see: Promise.
Methods Summarized
The catch() method of Promise instances schedules a function to be called when the promise is rejected.
The finally() method of Promise instances schedules a function to be called when the promise is settled (either fulfilled or rejected).
The then() method of Promise instances takes up to two arguments: callback functions for the fulfilled and rejected cases of the Promise.
The then() method of Promise instances takes up to two arguments: callback functions for the fulfilled and rejected cases of the Promise.
Methods Detailed
all(iterable)
The Promise.all() static method takes an iterable of promises as input and returns a single Promise. This returned promise fulfills when all of the input's promises fulfill (including when an empty iterable is passed), with an array of the fulfillment values. It rejects when any of the input's promises rejects, with this first rejection reason.
Parameters
Array iterable ;
Returns: Promise
allSettled(iterable)
The Promise.allSettled() static method takes an iterable of promises as input and returns a single Promise. This returned promise fulfills when all of the input's promises settle (including when an empty iterable is passed), with an array of objects that describe the outcome of each promise.
Parameters
Array iterable ;
Returns: Promise
js_catch(onRejected)
The catch() method of Promise instances schedules a function to be called when the promise is rejected. It immediately returns another Promise object, allowing you to chain calls to other promise methods. It is a shortcut for then(undefined, onRejected).
Parameters
Function onRejected ;
Returns: Promise
js_finally(onFinally)
The finally() method of Promise instances schedules a function to be called when the promise is settled (either fulfilled or rejected). It immediately returns another Promise object, allowing you to chain calls to other promise methods.
This lets you avoid duplicating code in both the promise's then() and catch() handlers.
Parameters
Function onFinally ;
Returns: Promise
race(iterable)
The Promise.race() static method takes an iterable of promises as input and returns a single Promise. This returned promise settles with the eventual state of the first promise that settles.
Parameters
Array iterable ;
Returns: Promise
reject(reason)
The Promise.reject() static method returns a Promise object that is rejected with a given reason.
Parameters
Object reason ;
Returns: Promise
resolve(value)
The Promise.resolve() static method "resolves" a given value to a Promise. If the value is a promise, that promise is returned; if the value is a thenable, Promise.resolve() will call the then() method with two callbacks it prepared; otherwise the returned promise will be fulfilled with the value.
This function flattens nested layers of promise-like objects (e.g. a promise that fulfills to a promise that fulfills to something) into a single layer — a promise that fulfills to a non-thenable value.
Parameters
Object value ;
Returns: Promise
then(onFulfilled)
The then() method of Promise instances takes up to two arguments: callback functions for the fulfilled and rejected cases of the Promise. It stores the callbacks within the promise it is called on and immediately returns another Promise object, allowing you to chain calls to other promise methods.
Parameters
Function onFulfilled ;
Returns: Promise
then(onFulfilled, onRejected)
The then() method of Promise instances takes up to two arguments: callback functions for the fulfilled and rejected cases of the Promise. It stores the callbacks within the promise it is called on and immediately returns another Promise object, allowing you to chain calls to other promise methods.
Parameters
Returns: Promise
Last updated
Was this helpful?