For your consideration, in addition to the technical reasons indicated in your quoted answer:
Matching promises
ES6 / A + compatible Promise instances:
- When a promise is resolved, its condition and value are unchanged.
- A promise cannot be kept with a promise.
- Then, the registered listener "execute" is never called with a promise (or other subsequent) object as an argument.
- The listeners registered
then execute asynchronously in their thread after the code that caused them to execute has completed. Regardless of whether the listener has been registered for a call back when the promise is settled (“fulfilled” or “rejected”),
- listener return value is used to
fulfill the resolution of the promise returned by its registration then - the value passed (using
throw ) by the listener is used to reject the promise returned by then , and
A promise resolved by a Promise instance is synchronized with the possible resolved state and value of the promise provided as an argument. (In the ES6 standard, this is described as "blocked").
- A promise resolved with a subsequent object that is not a Promise instance will skip synchronization as needed: if it is resolved first with thenable, which “fulfills” itself with thenable, the Promise promise will be re-synchronized with the last 'thenable'. A transition to a new synchronization cannot happen with A + promises, because they never call an "executable" listener followed by an object.
Not compatible promises
Potential characteristics of incompatible promising properties include
- letting you change the state of a promised promise,
- calling an "executed" listener with a promise argument,
- calling the listener, either for "worked out" or "dropped" states, synchronously from the code that allows or rejects the promise,
- does not reject the returned promise
then after the listener registered in the then call throws an exception.
Interoperability
Promise.resolve can be used to repay a promised promise with a static value, possibly mainly used in testing. Its main goal, however, is to quarantine the side effects of incompatible promises. The promise returned by Promise.resolve( thenable) will display all behaviors 1-7 above, and none of the incompatible behaviors.
IMHO I suggest using only non-a + objects on both sides in the environment and according to the documentation for the library that created them. An unauthorized thenable can be used to resolve an A + promise directly (which Promise.resolve does), but for complete predictability of behavior, it must be wrapped in a Promise object using Promise.resolve( thenable) before any other use.
Note. I tried checking Parse promises for A + compliance, but does not seem to provide a constructor. This leads to the fact that claims “almost” or “completely” match A + is difficult to quantify. Thanks to zangw to indicate the possibility of returning a rejected promise to form a listener as an alternative to exception.
source share