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

Option to set failOnError false while still throwing first error encountered #14

Closed
kitsunde opened this issue Jun 6, 2023 · 2 comments

Comments

@kitsunde
Copy link

kitsunde commented Jun 6, 2023

Hello,

I'm using this library to quickly replace calls that are currently Promise.all to avoid an issue with orphaned promises after one fails. However this throws an AggregateError on { failOnError: false } which changes the semantics.

It would be nice if it could keep the exception semantics, but still wait. I understand I can just replace things with allSettled or some such, although that also changes the semantics since the order of failure is lost.

@sindresorhus
Copy link
Owner

It won't leave promises pending with {stopOnError: true}. If promises are started, they will continue until they are done, but pAll won't await them or include their result. The proper way to handle this is with a signal. It should be pretty easy to include that here as it could just be passed down to p-map.

You can already solve your use-case by catching the error and re-throwing error.errors[0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError If you need it in multiple places, you could wrap it in the wrapper function.

@kitsunde
Copy link
Author

Thanks for the suggestions, I'm quite familiar with those language mechanics, but I'm afraid that wouldn't cover it.

I've wrapped it to throw by index and just handle it in that manner instead of rejection order and that's okay, thanks for the library! :)

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