Skip to content

Instantly share code, notes, and snippets.

@EvanCarroll
Last active January 4, 2016 10:59
Show Gist options
  • Save EvanCarroll/8612611 to your computer and use it in GitHub Desktop.
Save EvanCarroll/8612611 to your computer and use it in GitHub Desktop.
var co = require('co'),
Promise = require('bluebird')
;
// This just creates 3 identical generator functions.
(function (g) {
["foo","bar","baz"].forEach( function(x) {
g[x] = function * () {
let c = 0;
while (true && c<5) {
console.log( x + ' ' + c++ );
yield [];
}
//throw Error('DEAD'); // XXX: Dare you!! uncomment it
return {'var':x, 'count':c};
}
} );
})(global);
co( function* () {
try {
// parallel opperations
console.log( yield [foo,bar,baz] );
//synchronous opperations
console.log( yield foo );
console.log( yield bar );
}
catch ( e ) {
console.log({'Handeled error': e});
}
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment