title: Promise.all() is not resolving promises in the expected order
body: <p>If I understand Promise.all() correctly, I would expect this code to take 5 seconds before outputting <strong>only</strong> the reason for the rejected promise to the console.</p>
  
  <pre><code>function firstAsyncFunction() {
    return new Promise(function(resolve, reject){
      setTimeout(function(){
        resolve(console.log('First async function has been resolved!'));
      }, 500);
    });    
  }
  
  function secondAsyncFunction() {
    return new Promise(function(resolve, reject) {
      setTimeout(function(){
        resolve(console.log('Second async function has been resolved!'));
      }, 2000);
    });
  }
  
  function thirdAsyncFunction() {
    return new Promise(function(resolve, reject) {      
      setTimeout(function() {              
        reject('Internal server error'); // rejected for some reason
      }, 5000);    
    });
  };
  
  Promise.all([secondAsyncFunction(), firstAsyncFunction(), thirdAsyncFunction()])
      .then(function(values){        
        values.forEach(function(value){
          console.log(value);
        });
  
      }).catch(function(err){
        console.log(err);
      });
  </code></pre>
  
  <p>Instead, the first two promises resolve, <strong>then</strong> the final promise rejects. Additionally, the first two promises aren't even resolving in the order in which they are passed in to Promise.all(). Do I need to compose my promises differently to see the behavior I'm expecting?</p>
  
  <p><strong><em>Edited</em></strong></p>
  
  <p>Promise.all() does indeed wait until all the promises in the iterable passed into it resolve. My first clue was the fact that the console was outputting undefined (thanks Jaromanda X). If I remove the calls to console.log() in the resolve to firstAsyncFunction() and secondAsyncFunction() the following piece of code works exactly as I would expect:</p>
  
  <pre><code>function firstAsyncFunction() {
    return new Promise(function(resolve, reject){
      setTimeout(function(){
        resolve('First async function has been resolved!');
      }, 1000);
    });    
  }
  
  function secondAsyncFunction() {
    return new Promise(function(resolve, reject) {
      resolve('Second async function has been resolved!');      
    });
  }
  
  function thirdAsyncFunction() {
    return new Promise(function(resolve, reject) {      
      setTimeout(function() {      
        reject('Internal server error');
      }, 5000);
    });
  };
  
  Promise.all([
    thirdAsyncFunction(), 
    firstAsyncFunction(), 
    secondAsyncFunction()
  ])
   .then(function(values){        
     values.forEach(function(value){
       console.log(value);
     });
   })
   .catch(function(err){
     console.log(err);
   });
  </code></pre>
  
  <p>After five seconds I see "Internal server error" only. Promise.all() rejects the other promises even though they resolve sooner than the promise that was rejected. And yes, the values resolved by Promise.all() will be in the same order as the promises in the iterable passed in as a parameter. Thanks for all your help!</p>
  
  <p>One more example:</p>
  
  <pre><code>function firstAsyncFunction() {
    return new Promise(function(resolve, reject){
      setTimeout(function(){
        resolve('First async function has been resolved!');
      }, 1000);
    });    
  }
  
  function secondAsyncFunction() {
    return new Promise(function(resolve, reject) {
      resolve('Second async function has been resolved!');      
    });
  }
  
  function thirdAsyncFunction() {
    return new Promise(function(resolve, reject) {      
      setTimeout(function() {
        resolve({
          users: [
            { name: 'Ronnie', age: 22 },
            { name: 'Bobby', age: 21 },
            { name: 'Ricky', age: 21 },
            { name: 'Mike', age: 20 }
          ]
        });
      }, 5000);
    });
  };
  
  Promise.all([thirdAsyncFunction(), firstAsyncFunction(), secondAsyncFunction()])
    .then(function(values){        
      values.forEach(function(value){
        console.log(value);
      });
    })
    .catch(function(err){
      console.log(err);
    });
  </code></pre>
  
  <p>After five seconds, this code will output:</p>
  
  <pre><code>{ users: 
     [ { name: 'Ronnie', age: 22 },
       { name: 'Bobby', age: 21 },
       { name: 'Ricky', age: 21 },
       { name: 'Mike', age: 20 } ] }
  First async function has been resolved!
  Second async function has been resolved!
  </code></pre>
  
  <p>Exactly what we want.</p>