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

342
Visualizações
Changing code to use async await when using the async module

I have the following code to download my files from s3 buckets:

async function downloadS3Files(options) {
  let s3client = new s3fs(options.bucket, s3options),
    files = await s3client.readdirp(options.object);
  return new Promise((resolve, reject) => {
    eachLimit(files, maxAsync, (file, callback) => {
      if ("/" === file.slice("-1")) {
        return callback();
      }
      let source = `${options.object}/${file}`,
        destination = `_input/${source}`;
      debug(destination);
      mkdirp(dirname(destination)).then(() => {
        let stream = s3client.createReadStream(source).pipe(createWriteStream(destination));
        stream.on("error", reject);
        stream.on("close", callback);
      }).catch(reject);
    }, () => {
      resolve(options)
    });
  });
}

And it works... but i want to avoid the eachLimit part, because i can't make use of await inside of a Promise constructor. Is there any other module to help me deal with maximum of async operations in a Promise way?

Thank you.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Is there any other module to help me deal with maximum of async operations in a Promise way?

There are few modules that can help you with that:

  • https://www.npmjs.com/package/async-promises
  • https://www.npmjs.com/package/async-promise
  • https://www.npmjs.com/package/async-q
  • https://www.npmjs.com/package/async-as-promised

For more complicated scenarios you can use Task.js - see:

  • http://taskjs.org/

but it uses generators to yield promises instead of async/await.

about 4 years ago · Santiago Trujillo 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