Skip to content

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

@darksabrefr

Description

@darksabrefr

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 #1641 (comment)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions