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.
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:
For more complicated scenarios you can use Task.js - see:
but it uses generators to yield promises instead of async/await.