Async queue, filestream end how to know when both finished Async queue, filestream end how to know when both finished node.js node.js

Async queue, filestream end how to know when both finished


Firstly, I'm not sure how much of your snippet is pseudo code but var q.drain = ... is not valid javascript and should error. It should just be q.drain = as you're defining a property on an existing object not declaring a new variable. This could be why your drain function isn't firing if it isn't pseudo code.

There are a few ways you could achieve what I think you're trying to do. One would be to check the length of the queue in your end handler and set the drain function if there are still items to process.

.on('end', function(){  if(!q.length){    callDone();  }  else {    q.drain = callDone;  }});function callDone(){  done(null, responseLines);}

This is effectively saying "if the queue's been processed call done, if not, call done when it has!" I'm certain there are lots of ways to tidy up your code but hopefully this provides a solution to your specific problem.