title: Idiomatic way to wait for multiple callbacks in Node.js
body: <p>Suppose you need to do some operations that depend on some temp file. Since
  we're talking about Node here, those operations are obviously asynchronous.
  What is the idiomatic way to wait for all operations to finish in order to
  know when the temp file can be deleted?</p>
  
  <p>Here is some code showing what I want to do:</p>
  
  <pre><code>do_something(tmp_file_name, function(err) {});
  do_something_other(tmp_file_name, function(err) {});
  fs.unlink(tmp_file_name);
  </code></pre>
  
  <p>But if I write it this way, the third call can be executed before the first two
  get a chance to use the file. I need some way to guarantee that the first two
  calls already finished (invoked their callbacks) before moving on without nesting
  the calls (and making them synchronous in practice).</p>
  
  <p>I thought about using event emitters on the callbacks and registering a counter
  as receiver. The counter would receive the finished events and count how many
  operations were still pending. When the last one finished, it would delete the
  file. But there is the risk of a race condition and I'm not sure this is
  usually how this stuff is done.</p>
  
  <p>How do Node people solve this kind of problem?</p>