Skip to content

Instantly share code, notes, and snippets.

@mwq27
Created February 3, 2015 18:06
Show Gist options
  • Save mwq27/8346934be9a6451ae01d to your computer and use it in GitHub Desktop.
Save mwq27/8346934be9a6451ae01d to your computer and use it in GitHub Desktop.
Example of ES6 generator and a call to the nodejs Stripe API
var jobs = {
generatorCC(chargeId, amount) {
stripe.charges.capture(chargeId, {amount}, function(err, charge) {
if (err) {
it.throw(err);
}
it.next(charge);
}.bind(this));
},
testGen: function*() {
try {
var data = yield this.generatorCC('ch_msmms0', 1000);
console.log('Ummmmmm, the Data' , data);
} catch (e) {
console.log('error equals', e.message);
}
}
};
var it = jobs.testGen();
it.next();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment