Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

265
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda