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

Consider rejecting only on rejected Promises. #8

Closed
wtgtybhertgeghgtwtg opened this issue Mar 4, 2018 · 5 comments
Closed

Consider rejecting only on rejected Promises. #8

wtgtybhertgeghgtwtg opened this issue Mar 4, 2018 · 5 comments

Comments

@wtgtybhertgeghgtwtg
Copy link

According to the documentation, pMap returns

a Promise that is fulfilled when all promises in input and ones returned from mapper are fulfilled, or rejects if any of the promises reject.

But strictly speaking, it's

a Promise that is fulfilled when all promises in input and ones returned from mapper are fulfilled, or rejects if any of the promises reject, or mapper or options.concurrency are invalid, or mapper throws.

It's a subtle difference, especially if you're awaiting pMap or passing an async function as mapper.

@sindresorhus
Copy link
Owner

sindresorhus commented Mar 5, 2018

What would be the alternative here? If you're going to say, synchronously throwing, that's a no-go, as promises should always reject. I think the solution here is to just better document all the situations it could reject.

@wtgtybhertgeghgtwtg
Copy link
Author

Something like

pMap(['foo']); // Throws
pMap(['foo'], () => Promise.reject()); // Rejects

I guess I am suggesting throwing synchronously, but I would say that the Promise still always resolves or rejects, but the function that returns the Promise can throw.

@sindresorhus
Copy link
Owner

@wtgtybhertgeghgtwtg
Copy link
Author

I did not know that. Sorry for the bother.

@sindresorhus
Copy link
Owner

No worries. I did not know either before that tweet :)

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

2 participants