The ES6 promises spec, as per September 2013 TC39 meeting
The ES6 promises spec, as per September 2013 TC39 meeting
This proposal has progressed to the Draft ECMAScript 6 Specification, which is available for review on the official ECMAScript wiki. When referencing the promises specification, you should reference the draft ECMAScript 6 spec, and not this repository.
We are still using this repository as a way to fix the remaining issues with the promises specification, and as such it may be slightly ahead of the draft specification as we perform that work. However, we must emphasize it is only a staging ground.
A Promise is an object that is used as a placeholder for the eventual results of a deferred (and possibly asynchronous) computation.
Any Promise object is in one of three mutually exclusive states: fulfilled, rejected, and pending:
p is fulfilled if p.then(f, r) will immediately enqueue a Task to call the function f.p is rejected if p.then(f, r) will immediately enqueue a Task to call the function r.A promise said to be settled if it is not pending, i.e. if it is either fulfilled or rejected.
A promise is resolved if it is settled or if it has been "locked in" match the state of another promise. Attempting to resolve or reject a resolved promise has no effect. A promise is unresolved if it is not resolved. An unresolved promise is always in the pending state. A resolved promise may be pending, fullfilled, or rejected.
A PromiseCapability is a Record value used to encapsulate a promise object along with the functions that are capable of resolving or rejecting that promise object. PromiseCapability records are produced by the NewPromiseCapability abstract operation.
PromiseCapability Records have the fields listed in this table.
PromiseCapability Record Fields
Field Name
Value
Meaning
[[Promise]]
An object
An object that is usable as a promise.
[[Resolve]]
A function object
The function that is used to resolve the given promise object.
[[Reject]]
A function object
The function that is used to reject the given promise object.IfAbruptRejectPromise is a short hand for a sequence of algorithm steps that use a PromiseCapability record. An algorithm step of the form:
means the same things as:
The PromiseReaction is a Record value used to store information about how a promise should react when it becomes resolved or rejected with a given value. PromiseReaction records are created by the then method of the Promise prototype, and are used by a PromiseReactionTask.
PromiseReaction records have the fields listed in this table.
PromiseReaction Record Fields
Field Name
Value
Meaning
[[Capabilities]]
A PromiseCapability record
The capabilities of the promise for which this record provides a reaction handler.
[[Handler]]
A function object, or a String
The function that should be applied to the incoming value, and whose return value will govern what happens to the derived promise. If [[Handled]] is "Identity" it is equivalent to a function that simply returns its first argument. If [[Handler]] is "Thrower" it is equivalent to a function that throws its first argument as an exception.When CreateResolvingFunctions is performed with argument promise, the following steps are taken:
A promise reject function is an anonymous built-in function that has [[Promise]] and [[AlreadyResolved]] internal slots.
When a promise reject function F is called with argument reason, the following steps are taken:
A promise resolve function is an anonymous built-in function that has [[Promise]] and [[AlreadyResolved]] internal slots.
When a promise resolve function F is called with argument resolution, the following steps are taken:
"then")."PromiseTasks", ResolvePromiseViaThenableTask, (promise, resolution, then))."pending"."fulfilled".The abstract operation NewPromiseCapability takes a constructor function, and attempts to use that constructor function in the fashion of the built-in Promise constructor to create a Promise object and extract its resolve and reject functions. The promise plus the resolve and reject functions are used to initialise a new PromiseCapability record which is returned as the value of this abstract operation.
Promise constructor.NOTE: This abstract operation supports Promise subclassing, as it is generic on any constructor that calls a passed executor function argument in the same way as the Promise constructor. It is used to generalize static methods of the Promise constructor to any subclass.
A GetCapabilitiesExecutor function is an anonymous built-in function that has a [[Capability]] internal slot.
When a GetCapabilitiesExecutor function F is called with arguments resolve and reject the following steps are taken:
"pending"."rejected".The abstract operation IsPromise checks for the promise brand on an object.
The abstract operation TriggerPromiseReactions takes a collection of functions to trigger in the next Task, and calls them, passing each the given argument. Typically, these reactions will modify a previously-returned promise, possibly calling in to a user-supplied handler before doing so.
"PromiseTasks", PromiseReactionTask, (_reactioNo open issues yet, or sync has not completed.