Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

341
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!