title: How invoke code after await Promise.all.then in javascript?
body: <p>Consider example:</p>
  
  <p><strong>js</strong></p>
  
  <pre><code>"use strict";
  
  const input = [
      "https://www.google.ru",
      "https://www.google.ru",
      "https://www.google.ru",
      "https://www.google.ru",
      "https://www.google.ru"
  ];
  const createPhantomPool = require('phantom-pool');
  (async function() {
      console.log("start");
      const pool = createPhantomPool({max: input.length*2, min: input.length*2});
      let promises = [];
      input.forEach(url =&gt; promises.push(pool.use(async (instance) =&gt; {
          instance.createPage()
              .then(page =&gt; {
                  return page.open(url);
              }).then(() =&gt; console.log("load finished"))
              .catch(error =&gt; {
                  console.log(error);
              });
      })));
      await (Promise.all(promises).then(() =&gt; console.log("after then")));
      console.log("end");
  }());
  </code></pre>
  
  <p><strong>package.json</strong></p>
  
  <pre><code>"dependencies": {
    "aws-sdk": "^2.68.0",
    "es6-promise": "^4.1.0",
    "log4js": "^1.1.1",
    "moment-timezone": "^0.5.13",
    "phantomjs": "^2.1.7",
    "webpage": "^0.3.0"
  </code></pre>
  
  <p>I expecte that all promised will be finished and only after that <code>console.log("after then")</code> is called. But this example gives me the following output:</p>
  
  <pre><code>start
  after then
  end
  load finished
  load finished
  load finished
  load finished
  load finished
  </code></pre>
  
  <p>Why <code>after then</code> is printed before <code>load finished</code>???</p>