
To do so, the subclass's constructor must implement the same signature as the Promise() constructor - accepting a single executor function that can be called with the resolve and reject callbacks as parameters. They all support subclassing, which means they can be called on subclasses of Promise, and the result will be a promise of the subclass type. In other words, fulfills when any of the promises fulfills rejects when any of the promises rejects.Īll these methods take an iterable of promises ( thenables, to be exact) and return a new promise. Settles when any of the promises settles. Promise.any()įulfills when any of the promises fulfills rejects when all of the promises reject. Promise.allSettled()įulfills when all promises settle. The Promise class offers four static methods to facilitate async task concurrency: Promise.all()įulfills when all of the promises fulfill rejects when any of the promises rejects. Colloquially, "resolved" promises are often equivalent to "fulfilled" promises, but as illustrated in "States and fates", resolved promises can be pending or rejected as well. The States and fates document from the original Promise proposal contains more details about promise terminology.

You will also hear the term resolved used with promises - this means that the promise is settled or "locked-in" to match the eventual state of another promise, and further resolving or rejecting it has no effect. If the promise has already been fulfilled or rejected when a corresponding handler is attached, the handler will be called, so there is no race condition between an asynchronous operation completing and its handlers being attached.Ī promise is said to be settled if it is either fulfilled or rejected, but not pending. When either of these options occur, the associated handlers queued up by a promise's then method are called. The eventual state of a pending promise can either be fulfilled with a value or rejected with a reason (error).

This lets asynchronous methods return values like synchronous methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point in the future. It allows you to associate handlers with an asynchronous action's eventual success value or failure reason.


()Ī Promise is a proxy for a value not necessarily known when the promise is created.Object.prototype._lookupSetter_() Deprecated.Object.prototype._lookupGetter_() Deprecated.Object.prototype._defineSetter_() Deprecated.Object.prototype._defineGetter_() Deprecated.
