promises-aplus / promises-spec

An open standard for sound, interoperable JavaScript promises—by implementers, for implementers.
https://promisesaplus.com/
Creative Commons Zero v1.0 Universal
1.84k stars 164 forks source link

Promise Resolution Procedure 3.iii: What if then never calls its arguments? #258

Open jcsahnwaldt opened 7 years ago

jcsahnwaldt commented 7 years ago

In The Promise Resolution Procedure step 3.iii, cases a through d are considered:

If then is a function, call it with ... first argument resolvePromise, and second argument rejectPromise, where: a. If/when resolvePromise is called... b. If/when rejectPromise is called... c. If both resolvePromise and rejectPromise are called, or multiple calls... d. If calling then throws an exception e...

But what if then neither throws an exception nor calls one of its arguments? It may simply do nothing and return. Probably a rare case, but it looks like an omission to me. Or am I missing something?

domenic commented 7 years ago

In general, if a spec does not tell you to do something, then indeed, you do not do anything. That is implicit, and doesn't need to be spelled out.

paulstelian97 commented 6 years ago

Let's assume the original promise (which we should denote by the object promise) will eventually settle (that is, get resolved or rejected).

Then if you have set up the promise like promise.then(onResolve, onReject), then either of onResolve or onReject is called depending on the state of promise (if it's not a function, then the new promise will be equivalent to the old one), with the sole argument being the value or reason of the original promise. The resulting function may either return or throw, and returning will resolve the new promise, while throwing will reject the new promise.

Returning without any value is equivalent to returning void 0 (AKA undefined); in this case the new promise is fulfilled with the value undefined.