title: nodejs: wait for other methods to finish before executing
body: <p>say I have 2 methods:  </p>
  
  <pre><code>function A(callback) { ... }
  function B(callback) { ... }
  </code></pre>
  
  <p>I want to execute:<br>
      function C();<br>
  after both A and B are finished.<br>
  what we usually do is to put function C in the callback like:</p>
  
  <pre><code>A(function() {
    B(function() {
      C();
    });
  });
  </code></pre>
  
  <p>now if both A and B takes a long time, I don't want B to execute after A has been finished. instead I want to start them at the same time to enhance performance.<br>
  what I'm thinking is to implement something like a semaphore (not really a semaphore of course), it fires an event after both A and B are finished. so that I can call C from within the event.</p>
  
  <p>what I want to know is, is there any library implemented the above function already? I believe I'm not the first one who wants to do it.<br>
  any help is appreciated.</p>