title: Outer function being called before xmlhttprequest being done
body: <p>room.onPlayerChat is an outer event i have no control on it, When i try to use it i need to process something on message and checking player role through xmlhttprequest and wait for response then send message to room chat but it doesn't wait for it(xmlhttprequest) to return the player's role and send the normal message (normal player role), how to hang that outer event (room.onPlayerChat) and its needed to handle any room chat source.</p>
  <pre><code>const makeRequest = (method, url, data = {}) =&gt; {
    const xhr = new XMLHttpRequest();
    return new Promise(resolve =&gt; {
      xhr.open(method, url, true);
      xhr.onload = () =&gt; resolve({
        status: xhr.status,
        response: xhr.responseText
      });
      xhr.onerror = () =&gt; resolve({
        status: xhr.status,
        response: xhr.responseText
      });
      if (method != 'GET') xhr.setRequestHeader('Content-Type', 'application/json');
      data != {} ? xhr.send(JSON.stringify(data)) : xhr.send();
    })
  }
  
  room.onPlayerChat = async function (player,message) {
    let request = await makeRequest(&quot;GET&quot;, 'URL/TO/CHECK/PLAYER/ADMIN/ROLE' + player.name);
      
      if (request.response == &quot;YES&quot;)
      {
              room.sendmessage(&quot;ADMIN&quot; + player.name + message);
              return false;
      }
  }
  
  </code></pre>