Re: Synchronous postMessage for Workers?

On Thu, Nov 17, 2011 at 10:33 PM, David Levin <levin@chromium.org> wrote:

> Ah so the proposal is really only adding a new method only
> on DedicatedWorkerGlobalScope which send a synchronous message and
> something corresponding on Worker which can respond to this.
>

There's no need for a new sending method; only a receiving method.  To
reuse the original example:

  postMessage({action: "prompt_user", prompt: "How about a nice game of
chess?"});
  var msg = waitForMessage();
  if(msg && msg.data) { chess_game.begin(); }

The other side is as usual:

  worker.onmessage = function(e) { worker.postMessage(true); }

without caring which API the worker is using to receive the response.

Note that the nonblocking case should definitely work on all ports.
There's no risk of deadlocks when not blocking.

-- 
Glenn Maynard

Received on Friday, 18 November 2011 16:17:15 UTC