Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jcsahnwaldt opened this issue Aug 16, 2017 · 2 comments

Comments

@jcsahnwaldt
Copy link

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
Copy link
Member

domenic commented Aug 16, 2017

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants