Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created December 11, 2012 19:04
Show Gist options
  • Save aheckmann/4261107 to your computer and use it in GitHub Desktop.
Save aheckmann/4261107 to your computer and use it in GitHub Desktop.
function saveStuff (stuff, cb) {
var pending = 2;
A.findStuff(function (err, doc) {
if (err) return done(err);
stuff.x = doc.x;
done()
})
B.findOtherStuff(function (err, doc) {
if (err) return done(err);
stuff.y = doc.y;
done()
})
function done (err) {
if (done.err) return;
if (err) return cb(done.err = err);
--pending;
if (0 === pending) cb();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment