Awaitable q.push doesn't resolve when queue worker throws an error
See original GitHub issueawait q.push(task)
is not safe for use for the moment because the promise returned by q.push
never resolve nor reject if the queue worker throws an error. I understand that await q.push(task)
cannot throw an error because of the backward compatibility of this method and its optional callback parameter (the push and forget feature). A q.asyncPush(task)
method that rejects its promise shouldn’t be feasible ?
You can show the problem with this code (in node or browser without the require):
const async = require('async');
let pushResult;
(async () => {
const q = async.queue(async (task) => {
throw new Error('Bad thing');
});
try {
pushResult = q.push({some: 'data'});
await pushResult;
console.log('Error not catched');
} catch (e) {
console.log('Error catched');
}
})();
setTimeout(() => {
console.log('exit');
console.log(pushResult);
}, 1000);
_Originally posted by @darksabrefr in https://github.com/caolan/async/pull/1641#issuecomment-498191809_
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
asyncio : How to queue object when an exception occurs
Queue () asyncio.create_task(worker(q)) for i in range(5): # put 5 items to process await q.put(i) await q.join() asyncio.run(main())
Read more >async - Documentation - GitHub Pages
An async function for processing a queued task. If you want to handle errors from an individual task, pass a callback to q.push()...
Read more >How to solve Async queue process issues in Node.js
The issue occurred for some tasks whenever there is an error like missing/Invalid keys in the task object, the queue goes into an...
Read more >p-queue - npm
AbortError. The error thrown by queue. add() when a job is aborted before it is run. See signal .
Read more >Using promises - JavaScript - MDN Web Docs
When that's the case, any callbacks added to promise2 get queued ... its error is caught by the final (outer) catch only, and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I like the
asyncPush
idea.I’m considering making
q.push()
resolve with the error object. Would that be sufficient? I really don’t wan’t to giveunhandledRejection
s to the vast majority ofqueue
users.