3 ms·
gjs has something similar: http://git.gnome.org/browse/gjs/tree/modules/promise.js http://git.gnome.org/browse/gjs/tree/modules/promise.js You end up writing c
by joeshaw 15y ago
gjs has something similar: http://git.gnome.org/browse/gjs/tree/modules/promise.js 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.