title: WebAssembly blocks the web worker thread too
body: <p>This is related to the previous question <a href="https://stackoverflow.com/questions/50731650/is-it-possible-to-run-webassembly-code-async">WebAssembly in async code</a></p>
  
  <p>Basically, that question is about the problem of the WebAssembly blocking the main thread, and the answer to the question is to move the WebAssembly code to a web worker. That works.</p>
  
  <p>The problem now is that the WebAssembly blocks the onmessage() on the worker.</p>
  
  <p>My long running WebAssembly code has functions like play(), pause(), stop(), etc. The play() checks a pause flag and a stop flag periodically to determine if the play() should return. The pause() and the stop() are used to set those flags.</p>
  
  <p>The JavaScript main thread calls postMessage() to send a message to the worker, which further calls the play().</p>
  
  <p>Since the onmessage() is blocked, the worker will have no chance to receive further messages to do pause() or stop() until the play() is completed. That will defeat the very purposes of the pause/stop.</p>
  
  <p>It seems the simple use case of play/pause/stop cannot be supported by the WebAssembly.</p>
  
  <p>Any comments or suggestions?</p>
  
  <p>By the way, that use case is well supported by the defunct Google PNaCl.</p>
  
  <p>Thanks.</p>