Blocking message passing for Workers

I would find it extremely useful to have a function available to a Worker
that would block and wait for a message from another Worker or from the
main thread. For example, instead of:

onmessage = function(event) {
  // Do some work
  // Save all state for next time
};

I'd like to have something like this:

while (true) {
  var data = waitForMessage().data;
  // Do some work
}

or:

var subworker = new Worker('subworker.js');
while (true) {
  var data = subworker.waitForMessage().data;
  // Do some work
}

A timeout would probably be nice to have. I don't have an opinion on
whether having a timeout should be optional or required.

Of course you wouldn't want to do this in the main thread, just as you
wouldn't use a synchronous XMLHttpRequest. But it's fine to have a Worker
loop indefinitely and block while waiting for results from somewhere else.

Is this a possibility?

Is there already some way to do this that I'm not aware of?

Do I need to expand on my reasons for wanting such a thing?

Received on Friday, 8 August 2014 17:49:52 UTC