W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2012

Re: Synchronous postMessage for Workers?

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Tue, 14 Feb 2012 16:22:53 -0500
Message-ID: <4F3AD0AD.6060102@mit.edu>
To: public-webapps@w3.org
On 2/14/12 2:52 PM, Glenn Maynard wrote:
> I don't think this:
>
> function() {
>      f1();
>      yieldUntil(condition);
>      f2();
> }
>
> is any more racy than this:
>
> function() {
>      f1();
>      waitForCondition(function() {
>          f2();
>      });
> }

Let's say the function above is called "f", and consider this code:

var inG = false;
function g() {
   inG = true;
   h(); /* This function does things differently depending on
           whether inG is true */
   f();
   inG = false;
}

"g" is fine with the second snippet above, but broken with the first one.

So while in practice the two are equally racy, writing correct code that 
calls into the second snippet is much easier than writing correct code 
that calls into the first one.  And in practice, a developer would 
perceive the first snippet as being less racy than the second one, 
because the race is not nearly as obvious.

> I don't believe it's any more bug-prone than the equivalent
> callback-based code, either.

See above.  This is not a hypothetical issue.  We have some experience 
with APIs that look like the yieldUntil one above, and in practice it 
causes serious code maintainability problems because everything up the 
callstack has to make sure that it's data structures are in a consistent 
state before calling into functions.

> I believe continuations are less error
> prone than callbacks, because it leads to code that's simpler and easier
> to understand.

It leads to code that _looks_ simpler and easier to understand.  Whether 
it _is_ that way is an interesting question.

-Boris
Received on Tuesday, 14 February 2012 21:23:21 GMT

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