Single frame continuations proposal

Kris Zyp kris at
Thu Apr 1 05:54:29 PDT 2010

Hash: SHA1

On 3/31/2010 10:56 AM, David Herman wrote:
> Hi Kris,
> I've been poring over this for a while, and it's still really,
> really confusing. Could I ask you to show how you would write the
> following example with your proposal?
> function setup() {
> setFlashing(document.getElementById("notificationArea"));
> alert("done setup!"); }
> var flashingElts = [];
> function setFlashing(elt) { var toggle = true;
> window.setTimeout(function() { = toggle ?
> "red" : "white"; toggle = !toggle; }, INTERVAL);
> flashingElts.push(elt); }
I am not exactly sure what that intent is here, but I am guessing it
is supposed to flash several times before showing the alert. So maybe
we could do it with something like:

    function setup() {
        alert("done setup!"); // called after 10 flashes

    function setFlashing(elt) {
        for(var i = 0; i < 10; i++){ //toggle 10 times
            var toggle = true;
            sleep->(INTERVAL); // yield for each sleep
   = toggle ? "red" : "white";
            toggle = !toggle;

> And then would you mind showing a rough translation of your
> implementation to ES5 code (similar to the translation of your
> `foo' function)?
However, before getting more into the translation and implementation
of a delay function, something you said earlier...

> Your approach seems nicely Harmony-ous: small, simple, orthogonal.
> It would definitely be a cost, however, if there turned out to be
> some incompatibility with JS 1.7 generators. I don't think there is
> one, but it would be good to know-- and conversely, it'd be awesome
> if generators (minus the syntax) could really be implemented as a
> library, e.g. if "yield <expr>" could be simulated by calling:

This really lead me to think about if it would be possible to meet the
goals of this proposal *and* make this fully compatible (syntax and
default behavior) with JS 1.7 generators. That is make it compatible
with generators and still making it sufficiently extensible to meet
the broad range of needs that could utilize single-frame
continuations/coroutines. And I believe it is, and it could done in a
way that this proposal could be implemented in JavaScript as well
generators. Do you think it would be worth exploring that possibility?
I'll put a sketch together in another email for this alternate
approach, (if it doesn't sound good, we can revert back to digging
into this one).
>>>> 6. Resume *continuation*, using the value of *result* for
>>>> the continued evaluation of the current expression (if the
>>>> continuation is inside an expression).
>>> Is this supposed to fall through?
>> Yes
> That can't be true, can it? If step 6 continues to step 7 then we
> get:
> // step 5 if (!($result && typeof $result.continueWith ===
> "function")) { // do step 6 } // fall through var $waiting = true;
> var $continueWithResult = $result.continueWith($resume);
> But we established in step 5 that there's no $result.continueWith
> function.

You are right, once the continuation is resumed the algorithm is

- -- 
Kris Zyp
(503) 806-1841
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla -

More information about the es-discuss mailing list