title: How to await for a function or a database query? And then process results and finally send them back
body: <p>I have this scenario:</p>
  
  <pre><code>app.get('/', async function (request, response) 
  {
       await foo(DbConnection).then((result) =&gt; console.log("response ready"));
  })
  
  let foo = async function (DbConnection)
  {
      const myQuery = "SELECT * FROM my_table";
  
      DbConnection.query(myQuery, async function(err, results) {
         console.log("query ready");
         await bar(results).then((response) =&gt; console.log("bar done"))
      })
      return; // go back to app.get() to send stuff to client
  }
  
  let bar = async function (results)
  {   
      console.log("inside bar");
      await ThirdPartyAPI(result).then((value)) =&gt; return value);
  }
  </code></pre>
  
  <p>Briefly:</p>
  
  <ul>
  <li><p>I receive GET request from client</p></li>
  <li><p>I call foo() which query data base and apply functions on results</p></li>
  <li><p>I process results using third party API which takes time to finish</p></li>
  <li><p>I send final results back to client</p></li>
  </ul>
  
  <p>I am expecting to see:</p>
  
  <blockquote>
    <p>query ready -> inside bar -> bar done -> response ready</p>
  </blockquote>
  
  <p>But I instead see:</p>
  
  <blockquote>
    <p>response ready -> query ready -> inside bar -> bar done</p>
  </blockquote>
  
  <p>Client is receiving <code>undefined</code> since nothing was ready when <code>response.send()</code></p>
  
  <p>What could be the issue?</p>