-
-
Save laser/7664456 to your computer and use it in GitHub Desktop.
I.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess there are missing yield operators on line 15, 16, 17? :-)