Re: Synchronous postMessage for Workers?

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 UTC