- From: Jonas Sicking <jonas@sicking.cc>
- Date: Wed, 15 Feb 2012 01:39:15 -0500
- To: Glenn Maynard <glenn@zewt.org>
- Cc: Ian Hickson <ian@hixie.ch>, Joshua Bell <jsbell@chromium.org>, public-webapps@w3.org, David Levin <levin@chromium.org>
On Tue, Feb 14, 2012 at 2:52 PM, Glenn Maynard <glenn@zewt.org> wrote: > On Tue, Feb 14, 2012 at 10:07 AM, Jonas Sicking <jonas@sicking.cc> wrote: >> >> Spinning the event loop is very bug prone. When calling the yieldUntil >> function basically anything can happen, including re-entering the same >> code. Protecting against the entire world changing under you is very >> hard. Add to that that it's very racy. I.e. changes may or may not >> happen under you depending on when exactly you call yieldUntil, and >> which order events come in. > > > I don't think this: > > function() { > f1(); > yieldUntil(condition); > f2(); > } > > is any more racy than this: > > function() { > f1(); > waitForCondition(function() { > f2(); > }); > } The problem is when you have functions which call yieldUntil. I.e. when you have code like this: function doStuff() { yieldUntil("x"); }; now what looks like perfectly safe innocent code: function myFunction() { ... code here ... doStuff(); ... more code ... } The myFunction code might look perfectly sane and safe. However since the call to doStuff spins the event loop, the two code snippets can see entirely different worlds. Put it another way, when you spin the event loop, not only does your code need to be prepared for anything happening. All functions up the call stack also has to. That makes it very hard to reason about any of your code, not just the code that calls yieldUntil. / Jonas
Received on Wednesday, 15 February 2012 06:41:00 UTC