Comparing version 0.0.2 to 0.0.3
11
index.js
module.exports = function(afterAllCb) { | ||
var errorMessage ='"next" function called after the final callback.'+ | ||
' Make sure all the calls to "next" are on the same tick'; | ||
var calls = 0; | ||
var done = false; | ||
return function next(cb) { | ||
if (done) throw new Error(errorMessage); | ||
calls++; | ||
@@ -11,4 +15,7 @@ | ||
process.nextTick(function() { | ||
cb.apply(null, args); | ||
if (--calls === 0) afterAllCb(); | ||
if (cb) cb.apply(null, args); | ||
if (--calls === 0) { | ||
done = true; | ||
afterAllCb(); | ||
} | ||
}); | ||
@@ -15,0 +22,0 @@ } |
{ | ||
"name": "after-all", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Execute several async functions and get a callback when they are all done", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,2 +5,10 @@ # after-all | ||
## Installation | ||
You can install it with npm. | ||
``` | ||
npm install after-all | ||
``` | ||
## Simple example | ||
@@ -7,0 +15,0 @@ |
@@ -65,2 +65,23 @@ var afterAll = require('../index'); | ||
}); | ||
it('should work if the callback is not passed', function(done) { | ||
var next = afterAll(function() { | ||
done(); | ||
}); | ||
setTimeout(next(), 300); | ||
}); | ||
it('should throw an error if the "next" function is called after the final callback is called', function(done) { | ||
var next = afterAll(function() {}); | ||
next()(); | ||
process.nextTick(function() { | ||
try { | ||
next(); | ||
} catch(e) { | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4267
90
69