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

Re: Synchronous postMessage for Workers?

From: Rick Waldron <waldron.rick@gmail.com>
Date: Fri, 18 Nov 2011 13:33:52 -0500
Message-Id: <5CA2024D-484C-4F50-B3FB-BBA2E46969E2@gmail.com>
Cc: David Levin <levin@chromium.org>, Jonas Sicking <jonas@sicking.cc>, Joshua Bell <jsbell@chromium.org>, "public-webapps@w3.org" <public-webapps@w3.org>
To: Glenn Maynard <glenn@zewt.org>


On Nov 18, 2011, at 12:56 PM, Glenn Maynard <glenn@zewt.org> wrote:

> On Fri, Nov 18, 2011 at 12:18 PM, David Levin <levin@chromium.org> wrote:
> The primary use case is one in which messages sent to DedicatedWorkerGlobalScope are reserved for synchronous messaging.
> 
> Mostly, yes, or otherwise dealing with unrelated messages coming in while you're waiting for a response.
> 
> It's possible to safely use async and sync message receipt on the same channel.  For example,
> 
> onmessage = function(e)
> {
>     if(e.data.message == "pause")
>     {
>         msg = waitForMessage();
>         // assert(msg.message == "continue");

The name "waitForMessage()" definitely has a "promise/futures" connotation... 


>     }
> }
> 
> and in the main thread,
> 
> worker.postMessage({message = "pause"});
> alert("The worker is currently paused and waiting to be continued");
> worker.postMessage({message = "continue"});


My initial concerns aside and with no trolling intentions... The above literal expressions are all syntax errors, = should be :
> 
> Once you send "pause", events and timers in the worker will be deferred until you resume it.  Since messages are delivered in order, this is guaranteed to work.
> 
> (By the way, the above isn't why I prefer this API; I prefer it because it avoids adding more messaging mechanisms and it creates a simpler API.  The above is just an interesting way it might be used.)
> 
> -- 
> Glenn Maynard
> 
Received on Friday, 18 November 2011 18:34:27 GMT

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