title: async await Promise usage blocks forever on await
body: <p>The event handler for websocket connection (<code>wss.on</code>) is called that calls an async function <code>sendInitialState()</code>. There I call an async function (<code>getMetadata()</code>) that returns a Promise in which I do some async stuff. I resolve the promise,  <code>resolve(res)</code> is called, but <strong>the program still blocks on await</strong>, that is <code>console.log(metadata)</code> is never called.</p>
  
  <pre><code>wss.on('connection', (ws) =&gt; {
  
      sendInitialState();
  });
  
  const sendInitialState = async (ws) =&gt; {
  
      console.log('Sending initial state!');
      const metadata = await getMetadata();
      console.log('metadata:', metadata);
  };
  
  const getMetadata = async () =&gt; {
  
      return new Promise((resolve, reject) =&gt; {
          MongoClient.connect(url, (err, db) =&gt; {
              if (err) {reject(err);}
              else {
                db.collection("meta").findOne({type: 'a'}, (err, res) =&gt; {
                  if (err) reject(err);
                  else {
                      db.close();
                      console.log('Metadata found: ', res);
                      resolve(res);
                  }
  
                });
              }
          }); 
      });
  
  }
  </code></pre>
  
  <p>What is the reason my program blocks?</p>
  
  <p>(I tried adding async before outer <code>(ws) =&gt;</code>, but outcome is the same)</p>