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.
You end up writing code like:
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.