title: node promises.all() doesnt work as expected
body: <p>I'm trying to run a list of functions synchronously after a loop using <code>promise.all()</code> but my code doesn't work as expected. </p>
  
  <p>Does someone know what I did wrong?</p>
  
  <p>my code is :</p>
  
  <pre><code>var Promise = require('promise');
  var promises = [];
  
  for (var i = 0; i &lt; 3; i++) {
      console.log('push promise ' + i);
      promises.push(foo(i));
  }
  
  Promise.all(promises)
          .then(function (data) {
              console.log("done");
          });
  
  function foo(i) {
      return new Promise(function (resolve, reject) {
          console.log('---&gt; foo i ' + i);
          resolve('done foo ' + i);
  
      });
  }
  </code></pre>
  
  <p>but the output is </p>
  
  <pre><code>push promise 0
  ---&gt; foo i 0
  push promise 1
  ---&gt; foo i 1
  push promise 2
  ---&gt; foo i 2
  done
  </code></pre>
  
  <p>where I expect</p>
  
  <pre><code>push promise 0
  push promise 1
  push promise 2
  ---&gt; foo i 0
  ---&gt; foo i 1
  ---&gt; foo i 2
  done
  </code></pre>
  
  <p>Thank you in advance.</p>