W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

Re: Synchronous postMessage for Workers?

From: Glenn Maynard <glenn@zewt.org>
Date: Fri, 18 Nov 2011 11:16:44 -0500
Message-ID: <CABirCh_O0ZVb5=mgZQNEHMrC7o7cjW5FUzBKNeoufVF36Hr-+A@mail.gmail.com>
To: David Levin <levin@chromium.org>
Cc: Jonas Sicking <jonas@sicking.cc>, Joshua Bell <jsbell@chromium.org>, public-webapps@w3.org
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:48 GMT