Skip to content

Instantly share code, notes, and snippets.

@AndreasMadsen
Forked from dallonf/gist:307f9378526f46669d8b
Created November 15, 2012 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreasMadsen/dab751610e4a3f96ff14 to your computer and use it in GitHub Desktop.
Save AndreasMadsen/dab751610e4a3f96ff14 to your computer and use it in GitHub Desktop.
function doThingsWithItems(callback) {
var items = ["foo", "bar", "baz"];
var remaining = items.length + 1;
var d = domain.create();
d.run(function () {
items.forEach(function(item) {
doSomethingErrorProne(function() {
remaining -= 1;
if (remaining == 0) {
d.dispose();
callback(null);
}
});
});
});
d.once('error', function (err) {
d.dispose();
callback(err);
});
}
doThingsWithItems(function (err) {
// not in a domain
console.log(domain.active === undefined);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment