title: Dealing with asynchronous function
body: <p>I have just started programming with JS and Node, and I haven't got used to asynchronous stuff yet.
  Basically, i have the following code:</p>
  
  <pre><code>for (var i=0, len=sources.length; i&lt;len; i++) {
      processSource(sources[i], function(info) {
          doesOtherStuff(sources[i], info);
      });
  }
  </code></pre>
  
  <p>It doesn't really work, because, as <code>processSource</code> takes a while to finish, the function <code>doesOtherStuff</code> is called with unmatching arguments, like <code>sources[2]</code> and the processed info for <code>sources[0]</code>.</p>
  
  <p>What is the correct way of dealing with this? Is there something inherently wrong with the design of these functions. (both processSource and doesOtherStuff are my functions).</p>