Single frame continuations proposal

David Herman dherman at mozilla.com
Mon Apr 5 09:26:38 PDT 2010


[BTW, your quoted text got garbled.]

> In order to utilize leverage continuations with a function that
> execute multiple we would need to eliminate single-shot restriction.
> You could then create some library function that passed the
> continuation to the setInterval function to do something like:
>    var toggle = true;
>    intervalling->(INTERVAL);
>    elt.style.background =...

Your answers keep leaving out the definition of the function that you're calling via `->', which is supposed to be the part that creates the requisite object with `continueWith' etc. Examples don't do much good if they skip the part they were supposed to illustrate!

> But in this case, using the yielding call would be confusing and
> provide very little benefit. This is definitely not the type of
> scenario that it is designed for, normal anon functions work great
> here. This is geared for when a callback is used to execute the
> remainder of a sequence after the completion of an asynchronous that
> we see so often in JavaScript.

I know. I wanted an example that had *both* asynchronous *and* synchronous statements, to understand the control flow of your proposal better, but I also was trying to keep it short. Maybe you'd prefer this example, which more clearly separates the parts that would be expressed with `->':

    function setup() {
        getThreeThings(URL1, URL2, URL3);
        alert("done setup!");
    }
    
    function getThreeThings(url1, url2, url3) {
        getAndFrob(url1);
        getAndMunge(url2);
        getAndGrok(url3);
    }
    
    function getAndFrob(url) {
        var xhr = new SimpleXHR(url);
        xhr.get(function(data) {
            window.setTimeout(function() {
                frob(data);
            }, TIMEOUT);
        });
    }
    
    function getAndMunge(url) {
        var xhr = new SimpleXHR(url);
        xhr.get(function(data) {
            window.setTimeout(function() {
                munge(data);
            }, TIMEOUT);
        });
    }
    
    function getAndGrok(url) {
        var xhr = new SimpleXHR(url);
        xhr.get(function(data) {
            window.setTimeout(function() {
                grok(data);
            }, TIMEOUT);
        });
    }

Would you mind writing out how to express this program with your proposal? I'm just trying to understand. If you can help me with some examples I think I maybe able to help clarify your ideas.

> Do you prefer basing single-frame continuations on new non-latin
> character syntax instead of using the "yield" keyword (hadn't realized
> it was already reserved in ES5 strict-mode when I did the first proposal)?

I don't follow you. Non-latin?

Dave



More information about the es-discuss mailing list