title: Is there a better way to do this in node.js?
body: <p>I'm using node.js to make a call to redis to grab some data. The data then needs to be sorted to arrays - not a costly procedure but I need a function to execute asynchronously right after the sorting is done.</p>
  
  <p>If I write the function right after the sorting code, it will fire off before the array sorting stuff is done. So I see a couple of ways of solving this:</p>
  
  <p>1) Write for() loops where the next one starts when the previous one is at its last iteration; At the VERY end, put the asynchronous method to make sure it runs after all the loops are finished.</p>
  
  <p>2) Use setTimeout(). I'm uneasy about doing that because it seems like maybe depending on the size of arrays that need to be processed it might magically fire off too soon, or too late.</p>
  
  <p>Is there a better way to go about this than nesting for loops?</p>