p-map icon indicating copy to clipboard operation
p-map copied to clipboard

Introducing `throwOnError` option for comprehensive promise chain results

Open fr1sk opened this issue 6 months ago • 2 comments

I think this package is missing an important functionality, and that is to see the results of resolved promises when one of the promises from the promise chain gets rejected. When stopOnError is set to false if some of the promises are rejected, I am not able to get fulfilled results, instead, the error is thrown.

It would be good to have similar behavior like Promise.allSettled to see the results of the promises and their status. EG if resolved, we can see the resolved result and if rejected we can see the error.

Maybe we can have an additional option, throwOnError which will be true by default to not break the functionality, but have the ability to have the functionality explained above.

I am happy to open a PR if you would like to include this functionality in your package.

fr1sk avatar Jan 04 '24 18:01 fr1sk

I agree that this functionality would be useful, but I'm not 100% sure about the throwOnError option. It's a bit too similar sounding to the existing stopOnError option. We could make the behavior clear in the docs, but I would still like to brainstorm some alternatives. I do think it should be an option and not separate methods.

For now, you could use p-reflect with p-map.

sindresorhus avatar Jan 07 '24 12:01 sindresorhus

I agree that it sounds similar to stopOnError but the functionality is different, also it may change the way how pMap works since it will return different things in case this option is passed (similar to Promise.allSettled response). Maybe the better option is to create a new function pMapSettled that will be similar to Promise.allSettled but have the functionality of pMap like the option to choose a number of parallel executions.

I will create a PoC package and let you review it so that later on we can include that in your repo.

fr1sk avatar Jan 15 '24 10:01 fr1sk