Skip to content

Instantly share code, notes, and snippets.

@Orion98MC
Created July 24, 2012 16:43
Show Gist options
  • Save Orion98MC/3171102 to your computer and use it in GitHub Desktop.
Save Orion98MC/3171102 to your computer and use it in GitHub Desktop.
function whenDone(callback) {
var left = 0
, done = function() { if (--left === 0) { callback(); } };
return function doThis(work, n) {
if (typeof n !== 'undefined') left += n;
else left++;
process.nextTick(function(){ work(done); });
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment