News for hackers. Stuff that matters.
Re:Google Releases JavaScript.next to JavaScript Compiler Tr... by joeshaw on Wednesday May 04, 2011 @10:10AM (#2513863)
gjs has something similar: http://git.gnome.org/browse/gjs/tree/modules/promise.js

You end up writing code like:

    function doAsyncStuff() {
        let result = yield someAsyncCall();
        result = yield someOtherAsyncCall(result);

        if (result) {
            Promise.putReturnFromGenerator("foo");
        } else {
            throw new Error("No result!");
        }
    }

    let promise = Promise.fromGenerator(doAsyncStuff);
    promise.get(function(result) {
        print(result); // -> "foo"
    }, function(error) {
        print(error); // -> exception toString() -> "No result!"
    });
The nice thing is the synchronous feel of doAsyncStuff() although it's actually pausing at each yield, waiting for a callback, and continuing execution from there.

It would seem as though Traceur's deferred functions replace the need for the generators by doing the continuation through the "await" keyword.

There are no comments on this comment yet.