I'm trying p-queue
after using promise-queue
for some time. Given this background, I was expecting to see the whole queue failing if any of its tasks rejects. However, this does not seem to happen.
Here's an example:
// testPQueue.js
import * as PQueue from "p-queue";
async function processQueue() {
const queue = new PQueue();
queue.add(
() =>
new Promise((resolve, reject) =>
setTimeout(() => {
reject();
}, 500),
),
);
await queue.onIdle();
console.log("should not be here");
return 42;
}
(async () => {
try {
const result = await processQueue();
console.log(result);
} catch (e) {
console.log("could not process queue");
}
})();
node ./testPQueue.js
Instead of seeing could not process queue
in my stdout
, I get this:
should not be here
42
(node:13679) UnhandledPromiseRejectionWarning: undefined
(node:13679) 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:13679) [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.
How can I stop and reject the whole queue once any its tasks has failed?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too