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

Pool size and promise-rejections #9

Closed
czaefferer opened this issue Feb 13, 2019 · 1 comment
Closed

Pool size and promise-rejections #9

czaefferer opened this issue Feb 13, 2019 · 1 comment

Comments

@czaefferer
Copy link

If the poolLimit is bigger than the input array, an "UnhandledPromiseRejectionWarning" is caused for every rejection. Take for example this code:

const asyncPool = require('tiny-async-pool');
const handler = async () => {
  const poolLimit = 2;
  const timeout = i => new Promise((resolve, reject) => setTimeout(() => reject(i), i));
  await asyncPool(poolLimit, [100, 500, 300, 200], timeout).catch(error => {console.log(error);});
};
handler();

Every promise is rejected, so the pool stops and rejects after the very first rejection, and the output is:

100

This is working as expected, but once I increase the poolLimit to 5 (or more, as long as it's bigger than the number of elements in the input array), the output looks like this:

100
(node:6106) UnhandledPromiseRejectionWarning: 100
(node:6106) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6106) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:6106) UnhandledPromiseRejectionWarning: 200
(node:6106) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:6106) UnhandledPromiseRejectionWarning: 300
(node:6106) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:6106) UnhandledPromiseRejectionWarning: 500
(node:6106) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
@rxaviers
Copy link
Owner

Thanks for filing this issue! I'd be happy to accept a PR with a fix.

mhjam added a commit to mhjam/async-pool that referenced this issue Feb 20, 2020
Only fill the executing array if it will be needed.
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