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

343
Vistas
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 Respuestas
Responde la pregunta

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