title: Complicated use case for Node.js Async Module
body: <p>I have started using Node.js as my backend for performing different operations like DB queries/ API calls, etc. I was reading about Node.js <a href="https://github.com/caolan/async" rel="nofollow">Async</a> and decided to give it a try. It has been working for simple use cases where I want some tasks in parallel or series but somehow I have landed in a requirement where I need an optimal combination of series/parallel/waterfall techniques of Async.</p>
  
  <p>Use Case:</p>
  
  <p>I have following functions implemented with callbacks:</p>
  
  <pre><code>function A(input, callback) {
  ...
  callback(err,result);
  }
  
  
  function B(input1, input2, callback) {
  ...
  callback(err,result);
  }
  
  
  function C(input, callback) {
  ...
  callback(err,result);
  }
  
  
  function D(input, callback) {
  ...
  callback(err,result);
  }
  
  
  function E(input, callback) {
  ...
  callback(err,result);
  }
  </code></pre>
  
  <p>And their order of execution should be like:</p>
  
  <p>A -> [B -> D]<br>
  A -> [C -> E]</p>
  
  <ul>
  <li>B,D,C,E are executed after A. </li>
  <li>D is executed after B </li>
  <li>E is executed after C </li>
  <li>B is executed after A </li>
  <li><p>C is executed after A</p></li>
  <li><p>B,D and C,E are not dependent on one another, so they can be executed
  in paralled after A has completed execution. </p></li>
  <li><p>D is dependent on B and should be executed after B </p></li>
  <li>E is dependent on C and should be executed after C.</li>
  </ul>
  
  <p>Also, I need to pass data from each of the functions to their dependent functions. So, A should be paasing result to B and C. Similarly B passing to D and C passing to E.</p>
  
  <p>How can I execute them efficiently using Async module ?</p>
  
  <p>I think I need something like but not sure though:</p>
  
  <pre><code>async.waterfall(    
    A: ...,    
    async.parallel(
        async.waterfall (
            B,
            D
        ),
        async.waterfall (
            C,
            E
        )
     )
  ) 
  </code></pre>