Skip to content

Instantly share code, notes, and snippets.

@laser
Created November 26, 2013 19:21
Show Gist options
  • Save laser/7664456 to your computer and use it in GitHub Desktop.
Save laser/7664456 to your computer and use it in GitHub Desktop.
I.js
function sync(gen) {
var iterable, resume;
resume = function(err, retVal) {
if (err) iterable.raise(err); // raise!
iterable.next(retVal);
};
iterable = gen(resume);
iterable.next();
}
sync(function* (resume) {
try {
var x = firstAsync(resume);
var y = secondAsync(resume);
var z = thirdAsync(resume);
// … do something with your data
}
catch (e) {
console.log(e); // will catch errors from any of the three calls
}
});
@jslu
Copy link

jslu commented Apr 11, 2015

I guess there are missing yield operators on line 15, 16, 17? :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment