title: How do you wait to return a value until promise is resolved?
body: <p>I'm trying to write a function that doesn't return it's value until a Promise inside the function has resolved. Here's a simplified example of what I'm trying to do. </p>
  
  <pre><code>'use strict';
  
  function get(db, id) {
       let p = db.command('GET', 'group:${id}');
       p.then(g =&gt; {
           g.memberNames = [];
           g.members.forEach(id =&gt; {
               User.get(db, id)
                   .then(profile =&gt; g.memberNames.push(profile.name))
                   .catch(err =&gt; reject(err));
           });
           return g;
      });
  }
  </code></pre>
  
  <p>It's a function that requests a group id and returns the data for that group. Along the way it's also throwing in the user's names into the data structure to display their names instead of their user id. My issue is that this is running asynchronously and will skip over the .then callbacks. By the time it gets to return g none of the callbacks have been called and <code>g.memberNames</code> is still empty. Is there a way to make the function wait to return g until all callbacks have been called?</p>
  
  <p>I've seen a lot of stuff about await. Is this necessary here? It's highly undesired to add other libraries to my project.</p>