Skip to content

Instantly share code, notes, and snippets.

@epall
Created October 23, 2012 15:35
Show Gist options
  • Save epall/3939513 to your computer and use it in GitHub Desktop.
Save epall/3939513 to your computer and use it in GitHub Desktop.
example of JavaScript "coroutines" in practice
var async = require('async');
async.waterfall([
Foo.create.bind(Foo, fooId, false),
function(foo, cb) {
Bar.create(barId, '0000000000000001', false, null, utils.randomID(12), cb);
},
function(result, cb) {
Baz.create('baz_'+utils.randomID(4), true, 1, 'hello, world', cb);
},
function(baz, cb) {
var thingy = new Thingy({id: thingyId});
thingy.associateWithBaz(baz.id, baz.account_id, cb);
},
function(cb) {
var message = { command: 'hello', arch: 4 };
something.handle(message, cb);
},
], function(err, result) {
test.ok(!err, err);
test.done();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment