Home Wait until all tasks finish in queue to return the value , using async library
Reply: 0

Wait until all tasks finish in queue to return the value , using async library

user665
1#
user665 Published in May 21, 2018, 6:42 pm

I have used async library to do some tasks concurrently, using the queue, my problem is I update the result inside drain, but when I return the result at end of function, it's still have initial value. should I use promise and async/await again on the queue? this is my code :

result = false;
const q = async.queue((task, callback) => {
console.log('Uploading : ', task.src)
s3.upload({
  Bucket: outputBucket,
  Key: task.desc,
  Body: fs.createReadStream(task.src)
}, callback)
}, PARALLEL_TASK)

q.drain = function() {result= true;}

q.push(fileNamesReformat)

return result; // HERE It's still false!
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.337123 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO