Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

262
Vistas
async.queue with async handler function - callback argument undefined

I have a queue that consumes commands based on https://caolan.github.io/async/v3/docs.html#queue with an async function, because the processing requires async/await.

this.commandQueue = async.queue(async (task, callback) =>
{
  await this.sleep(10); // Long running async stuff
  callback(null, data);
}, 1);

The result of the task shall be sent back via 'data'.

this.commandQueue.push(
{
 ...command data
}, function (err, data)
{
 // called when task finished - callback called
 ... // data is undefined
});

Issue: 'data' is undefined.

When I remove async /await from the top function section, it works, but I can't call my long-running task :-(

I have no idea how to solve this issue. Any hints?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

See here https://caolan.github.io/async/v3/global.html. Async function won't get the callback argument from ES2017 on. Have a look what ES version you're using.

Workaround is be make the worker function not "async" but promised based. If anyone knows how to fix it without switching to promises, comment would be appreciated.

// async bases
async function worker(opts, callback) { // callback will be undefined}
const q = async.queue(worker)

//promised based
function worker(opts, callback) { // callback will work as expected}
const q = async.queue(worker)

Wherever we accept a Node-style async function, we also directly accept an ES2017 async function. In this case, the async function will not be passed a final callback argument, and any thrown error will be used as the err argument of the implicit callback, and the return value will be used as the result value. (i.e. a rejected of the returned Promise becomes the err callback argument, and a resolved value becomes the result.)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda