sindresorhus / p-limit

Run multiple promise-returning & async functions with limited concurrency
MIT License
1.97k stars 102 forks source link

Fix error on invalid concurrency #35

Closed sethp closed 4 years ago

sethp commented 4 years ago

Else, passing in an invalid concurrency (in my case, because I wanted to see if -1 meant "unlimited") produces a confusing error message: both a limit is not a function at the point of use, and an UnhandledPromiseRejectionWarning from node itself.

An example:

const limit = pLimit(userSuppliedValue || someDefault);

...
.map(val => limit(() => doSomething()))
//               ^ TypeError: limit is not a function
...
sethp commented 4 years ago

A question I had is whether it would make more sense to throw the type error straightaway rather than defer it until promise resolution time?

sindresorhus commented 4 years ago

A question I had is whether it would make more sense to throw the type error straightaway rather than defer it until promise resolution time?

Yes. That's better. Can you update the tests?