Skip to content

Instantly share code, notes, and snippets.

@deepak
Created February 3, 2015 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepak/9a7337d7a641f8af9c8b to your computer and use it in GitHub Desktop.
Save deepak/9a7337d7a641f8af9c8b to your computer and use it in GitHub Desktop.
cannot throw error from ES6 generator
function getStockPrice() {
seq.throw('oops! could not get stock price');
// seq.next(80);
}
function executeTrade() {
setTimeout(function() {
console.log("trade done");
seq.next(true);
}, 300);
}
var stockTrade = function* () {
try {
var price = yield getStockPrice();
console.log('toots');
if(price > 45) {
executeTrade();
} else {
console.log('trade not done');
}
} catch(ex) {
// always says:
// caught error: Generator is already running
// expected "oops! could not get stock price"
console.log("caught error: " + ex.message);
}
}
var seq = stockTrade();
seq.next(); // {value: undefined, done: true}
@deepak
Copy link
Author

deepak commented Feb 4, 2015

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