title: JavaScript event not triggered (sync connection with websockets)
body: <p>I'm developing an app with websockets. I have an event that it's called when a message it's received but it doesn't fire if I have a loop.
  What I'm trying to do it's a sync connection (only for this part, that's why I'm using websockets). My idea it's to wait until the message received it's what I expect and then continue the program flow.</p>
  
  <pre><code>var connection = new WebSocket('ws://' + location.hostname + ':8888/')
  var msgAck=false; //Flag that comes true when received data
  
  connection.onmessage = function (event){
    check(event.data);
  }
  
  function check(msg){
    if(msg == "ok")msgAck=true;
  }
  
  function requestOk(){
    connection.send("somecmd");
  }
  //Normal program flow
  requestOk();//Server will return "ok"
  while(!msgAck);//Wait server response
  </code></pre>
  
  <p>The <code>onmessage</code> event it's never triggered so the program get stuck there.</p>