Skip to content

Instantly share code, notes, and snippets.

@alemures
Created June 23, 2016 14:02
Show Gist options
  • Save alemures/2ef056a1d6b0ba7af34329b16174adb9 to your computer and use it in GitHub Desktop.
Save alemures/2ef056a1d6b0ba7af34329b16174adb9 to your computer and use it in GitHub Desktop.
Yield Promises
function run(generator) {
var it = generator();
var obj = it.next();
(function _run() {
if (!obj.done) {
obj.value.then(result => {
obj = it.next(result);
_run();
}).catch(err => it.throw(err));
}
}());
}
// Example of usage
run(function*() {
try {
var app = yield getApp(12312);
var user = yield getUser(23123);
console.log(app, user);
} catch(e) {
console.error(e);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment