I have a huge piece of code (compiled with Emscripten) running inside a web worker. The page kicks off a task in the worker with one postMessage, and when the worker is finished, it sends another postMessage back. Great. However, I have a new feature I'd like to add that requires me to pause the worker mid-execution, kick a message back to the browser via postMessage, wait for the user to submit a valid response via postMessage, and then finish execution. However, I can't figure out anything that works. My attempts to have the worker wait in an infinite loop until a control variable is set on arrival of the message fails because the infinite loop prevents the execution of the worker's message handler. I can break out of the worker execution by throwing an exception, but then I have no idea how to resume execution. 

Does anyone have any ideas?