question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Awaitable q.push doesn't resolve when queue worker throws an error

See original GitHub issue

await 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:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
aearlycommented, Jun 13, 2019

I like the asyncPush idea.

1reaction
aearlycommented, Jun 6, 2019

I’m considering making q.push() resolve with the error object. Would that be sufficient? I really don’t wan’t to give unhandledRejections to the vast majority of queue users.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found