title: Why is a second then returned before the first?
body: <p>I'm trying to understand ES6 promises, and for a second there, I thought I had it, but I guess not.</p>
  
  <p>So I want to create / read a bunch of files and only after this operation has completed, move on to do the next operation. To me, this lends itself nicely to Promises, but I'm getting confused as to why my second operation is returning before my first operation has completed.</p>
  
  <p>I've created a function <code>ensureFileExists</code> which returns a promise, and I pass this as a callback into <code>fileNames.map</code>. This logs an  array of <code>true</code> to the console, which is what I'd expect. But my confusion is, I thought that my seconded <code>then</code> would only get called after my first <code>then</code> has completed.</p>
  
  <p>If anyone could elaborate on why my second <code>then</code> is returning before my first <code>then</code>, I'd be grateful.  </p>
  
  <pre><code>getFileNames(ensureFileExists) {
    for(let i = 0; i &lt; this.fileCount; i++) {
      this.fileNames.push(this.generateRandomfileNames());
    };
    Promise.all(this.fileNames.map((file) =&gt; ensureFileExists(file)))
           .then(values =&gt; console.log(values))
           .then(console.log(1)) // Why is this logged before values???
           .catch(err =&gt; console.log(err))
  };
  
  ensureFileExists(file) {
    return new Promise((resolve, reject) =&gt; {
      let filePath = path.join(this.src, file);
  
      fsExtra.ensureFile(filePath, (err) =&gt; {
        if (err === 'undefined') {
          reject(new Error('Error creating file'));
        } else {
          resolve(true);
        }
      });
    })
  };
  </code></pre>