Skip to content

Commit

Permalink
See #5. Switch terminology from broken to rejected, and use onFulfill…
Browse files Browse the repository at this point in the history
…ed/onRejected as callback names to avoid confusion with fufilled/rejected state names
  • Loading branch information
briancavalier committed Oct 29, 2012
1 parent c89f05c commit b002072
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions promises-a-plus.md
Expand Up @@ -13,23 +13,23 @@ This specification borrows heavily from the [Promises/A proposal](http://wiki.co
## Terminology

1. "value" is any legal language value, including `undefined`, that is not a promise.
1. "reason" is a value. The term "reason" is used here because it is used in existing promise literature, and helps to reinforce the difference between fulfilled and broken promise states. It also conveys the intent that a reason should represent the "reason the associated promise has been broken."
1. "reason" is a value. The term "reason" is used here because it is used in existing promise literature, and helps to reinforce the difference between fulfilled and rejected promise states. It also conveys the intent that a reason should represent the "reason the associated promise has been rejected."
1. "must not change" means immutable identity (e.g. `===`), and does not imply deep immutability.

## Requirements

### General

A promise represents a value that may not be available yet. A promise must be one of three states: pending, fulfilled, or broken:
A promise represents a value that may not be available yet. A promise must be one of three states: pending, fulfilled, or rejected:

1. In the pending state, a promise
1. must provide a way to arrange for a function to be called with its fulfillment value after it has transitioned to the fulfilled state, or with its reason for being broken after it has transitioned to the broken state.
1. may transition to either the fulfilled or broken state.
1. must provide a way to arrange for a function to be called with its fulfillment value after it has transitioned to the fulfilled state, or with its reason for being rejected after it has transitioned to the rejected state.
1. may transition to either the fulfilled or rejected state.
1. In the fulfilled state, a promise
1. must have a value, which must not change.
1. must provide a way to arrange for a function to be called with that value.
1. must not transition to any other state.
1. In the broken state, a promise
1. In the rejected state, a promise
1. must have a reason, which must not change.
1. must provide a way to arrange for a function to be called with that reason.
1. must not transition to any other state.
Expand All @@ -38,34 +38,34 @@ A promise represents a value that may not be available yet. A promise must be o

A promise is an object or function that defines a `then` method that accepts the following two arguments:

promise.then(fulfilled, broken)
promise.then(fulfilled, rejected)

1. Both `fulfilled` and `broken` are optional arguments.
1. If `fulfilled` is a function,
1. it must be called after `promise` is fulfilled, with `promise`'s fulfillment value as its first argument.
1. Both `onFulfilled` and `onRejected` are optional arguments.
1. If `onFulfilled` is a function,
1. it must be called after `promise` is fulfilled, with `promise`'s value as its first argument.
1. it must not be called more than once.
1. it must not be called if `broken` has already been called.
1. If `fulfilled` is not a function, it must be ignored.
1. If `broken` is a function,
1. it must be called after `promise` is broken, with `promise`'s reason as its first argument.
1. it must not be called if `onRejected` has already been called.
1. If `onFulfilled` is not a function, it must be ignored.
1. If `onRejected` is a function,
1. it must be called after `promise` is rejected, with `promise`'s reason as its first argument.
1. it must not be called more than once.
1. it must not be called if `fulfilled` has already been called.
1. If `broken` is not a function, it must be ignored.
1. `fulfilled` and `broken` must not be called before `then` returns.
1. `fulfilled` and `broken` supplied in one call to `then` must never be called after those supplied to a later call to `then` on the same promise.
1. it must not be called if `onFulfilled` has already been called.
1. If `onRejected` is not a function, it must be ignored.
1. `onFulfilled` and `onRejected` must not be called before `then` returns.
1. `onFulfilled` and `onRejected` supplied in one call to `then` must never be called after those supplied to a later call to `then` on the same promise.
1. `then` may be called any number of times.
1. `then` must return a promise [[1](#recommendations)]

var promise2 = promise1.then(fulfilled, broken)
var promise2 = promise1.then(fulfilled, rejected)

1. If `fulfilled` is not a function and `promise1` is fufilled, `promise2` must be fulfilled with the same fulfillment value.
1. If `broken` is not a function and `promise1` is broken, `promise2` must be broken with the same reason.
1. If either `fulfilled` or `broken` returns a value, `promise2` must be fulfilled with that value.
1. If either `fulfilled` or `broken` throws an exception, `promise2` must be broken with the thrown exception as the reason.
1. If either `fulfilled` or `broken` returns a promise (call it `returnedPromise`), `promise2` must be placed into the same state as `returnedPromise`:
1. If `returnedPromise` is fulfilled, `promise2` must be fulfilled with the same fulfillment value.
1. If `returnedPromise` is broken, `promise2` must be broken with the same reason.
1. If `returnedPromise` is pending, `promise2` must also be pending. When `returnedPromise` is fulfilled, `promise2` must be fulfilled with the same fulfillment value. When `returnedPromise` is broken, `promise2` must be broken with the same reason.
1. If `onFulfilled` is not a function and `promise1` is fufilled, `promise2` must be fulfilled with the same fulfillment value.
1. If `onRejected` is not a function and `promise1` is rejected, `promise2` must be rejected with the same reason.
1. If either `onFulfilled` or `onRejected` returns a value, `promise2` must be fulfilled with that value.
1. If either `onFulfilled` or `onRejected` throws an exception, `promise2` must be rejected with the thrown exception as the reason.
1. If either `onFulfilled` or `onRejected` returns a promise (call it `returnedPromise`), `promise2` must be placed into the same state as `returnedPromise`:
1. If `returnedPromise` is fulfilled, `promise2` must be fulfilled with the same value.
1. If `returnedPromise` is rejected, `promise2` must be rejected with the same reason.
1. If `returnedPromise` is pending, `promise2` must also be pending. When `returnedPromise` is fulfilled, `promise2` must be fulfilled with the same value. When `returnedPromise` is rejected, `promise2` must be rejected with the same reason.

## Recommendations

Expand Down

0 comments on commit b002072

Please sign in to comment.