title: socket.io control execution order with nested async and await
body: <p>In my app, I have multiple users submitting data "at once" via a socket.event.
  Because I need to know if every user has submitted their data successfully, I try to indentify the first and last entry.
  For that, I call an async function on the event, which itself includes "await".</p>
  
  <p>Basically, the function looks for a value in the database and then does something depending on whether it exists or not.</p>
  
  <p>Because of that, I need the function block (with its awaits) to be fully executed before the next instance of the function is called. </p>
  
  <p>However, what I found is that the as soon as I call await inside the function, the next instance of said function starts executing, which obviously messes everything up.</p>
  
  <pre><code>    socket.on("entries", async entries =&gt; {
  
          const firstEntry = await match.noEntries(mid);
          if (firstEntry) {
              //do sth
          }
  
          await match.submitEntries(mid, socket.pid, entries);        
  
      });
  
  //FUNCTION
  
  noEntries: async (mid) =&gt; {
      const entries = await database.query("...");
      return (entries.length == 0);
  }
  </code></pre>
  
  <p>Is there any way I can prevent the next instance of the function to be executed before it's predecessor has finished?</p>
  
  <p>Thanks in advance!</p>