title: Return only after each item has finished its method calls
body: <p>I've been struggling with the asynchronous nature of javascript in this project for a while now.</p>
  <p>There are a lot of similar questions on this topic, but I feel they are all slightly different and have made it difficult for me to get a working solution.</p>
  <p>I've been trying to create an api with these methods.</p>
  <ul>
  <li>getAll - an async file read</li>
  <li>audit</li>
  <li>auditAll</li>
  </ul>
  <p>I started writing all my methods with callbacks which was okay while it was simple. But now it's causing me issues. So I've written some wrappers with util.promisify which has worked great.</p>
  <p>I have this audit method which works perfectly.</p>
  <pre class="lang-js prettyprint-override"><code>const audit = (req, res, next) =&gt; {
      Domains.audit(req.params.url)
          .then((data) =&gt; { 
              res.json(data);
          })
          .catch((err) =&gt; {
              res.json(err);
          })
  };
  </code></pre>
  <p>It returns this object which is planned to be assigned to &quot;messages&quot;</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;warnings&quot;: [
          &quot;This url 301 redirects to https://www.google.com. Please update your entry.&quot;
      ],
      &quot;errors&quot;: []
  }
  </code></pre>
  <p><strong>Here's the problem.</strong></p>
  <p>I'm struggling to implement the auditAll method.
  I've tried using callbacks and promises, but it always returns before my audit calls modify the &quot;report&quot; I return</p>
  <p>Here's some pseudocode of what I keep failing to create</p>
  <pre class="lang-js prettyprint-override"><code>auditAll(callback) {
      // Get all domains with getAll() and make them look like this
      report = {
          '123' : {
              'url' : 'https://google.com',
              'other_props' : '...'
          }
          '124' : {
              'url' : 'https://google2.com',
              'other_props' : '...'
          }
      };
  
      // For each report item
          // run an audit which returns a message object
          // assign that to it's spot in the report
          report[item_key][messages] = audit(item.url)
      
      // Report returns to the browser before the audits finish with every solution I've implemented. 
      // They send to my console like 50ms later.
      callback(report)
  }
  </code></pre>