Comparing version 0.6.0 to 0.7.0
module.exports = after | ||
function after(count, callback) { | ||
function after(count, callback, err_cb) { | ||
var bail = false; | ||
proxy.count = count | ||
@@ -9,8 +10,17 @@ | ||
function proxy(err) { | ||
if (proxy.count <= 0) { | ||
throw new Error('after called too many times'); | ||
} | ||
--proxy.count; | ||
// after first error, rest are passed to err_cb | ||
if (err) { | ||
return callback(err) | ||
bail = true | ||
callback(err); | ||
// future error callbacks will go to error handler | ||
return callback = (err_cb || function() {}) | ||
} | ||
proxy.count === 0 && !bail && callback() | ||
} | ||
} | ||
--proxy.count === 0 && callback() | ||
} | ||
} |
{ | ||
"name": "after", | ||
"description": "after - tiny flow control", | ||
"version": "0.6.0", | ||
"author": "Raynos <raynos2@gmail.com>", | ||
"contributors": [ | ||
{ "name": "Raynos", "email": "raynos2@gmail.com", "url":"http://raynos.org" } | ||
], | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"devDependencies": { | ||
"mocha": "0.10.2" | ||
}, | ||
"keywords": ["flowcontrol", "after", "flow", "control", "arch"], | ||
"repository": "git://github.com/Raynos/after.js.git", | ||
"main": "lib/after" | ||
"name": "after", | ||
"description": "after - tiny flow control", | ||
"version": "0.7.0", | ||
"author": "Raynos <raynos2@gmail.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Raynos", | ||
"email": "raynos2@gmail.com", | ||
"url": "http://raynos.org" | ||
} | ||
], | ||
"scripts": { | ||
"test": "mocha --ui tdd --reporter spec test/*.js" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.8.1" | ||
}, | ||
"keywords": [ | ||
"flowcontrol", | ||
"after", | ||
"flow", | ||
"control", | ||
"arch" | ||
], | ||
"repository": "git://github.com/Raynos/after.git", | ||
"main": "lib/after" | ||
} |
@@ -67,4 +67,4 @@ # After [![Build Status][1]][2] | ||
[1]: https://secure.travis-ci.org/Raynos/after.js.png | ||
[2]: http://travis-ci.org/Raynos/after.js | ||
[1]: https://secure.travis-ci.org/Raynos/after.png | ||
[2]: http://travis-ci.org/Raynos/after | ||
[3]: http://raynos.org/blog/2/Flow-control-in-node.js | ||
@@ -76,2 +76,2 @@ [4]: http://stackoverflow.com/questions/6852059/determining-the-end-of-asynchronous-operations-javascript/6852307#6852307 | ||
[8]: http://github.com/Raynos/iterators | ||
[9]: http://github.com/Raynos/composite | ||
[9]: http://github.com/Raynos/composite |
/*global suite, test*/ | ||
var assert = require("assert"), | ||
after = require("../lib/after.js"); | ||
var assert = require("assert") | ||
, after = require("../") | ||
suite("After", function () { | ||
test("exists", function () { | ||
assert(typeof after === "function", "after is not a function"); | ||
assert(after.forEach, "forEach"); | ||
assert(after.map, "map"); | ||
assert(after.reduce, "reduce"); | ||
assert(after.reduceRight, "reduceRight"); | ||
assert(after.every, "every"); | ||
assert(after.filter, "filter"); | ||
assert(after.some, "some"); | ||
test("exists", function () { | ||
assert(typeof after === "function", "after is not a function") | ||
}) | ||
test("after when called with 0 invokes", function (done) { | ||
after(0, done) | ||
}); | ||
test("after 1", function (done) { | ||
var next = after(1, done) | ||
next() | ||
}) | ||
test("after 5", function (done) { | ||
var next = after(5, done) | ||
, i = 5 | ||
while (i--) { | ||
next() | ||
} | ||
}) | ||
test("manipulate count", function (done) { | ||
var next = after(1, done) | ||
, i = 5 | ||
next.count = i | ||
while (i--) { | ||
next() | ||
} | ||
}) | ||
test("after terminates on error", function (done) { | ||
var next = after(2, function(err) { | ||
assert.equal(err.message, 'test'); | ||
done(); | ||
}) | ||
next(new Error('test')) | ||
next(new Error('test2')) | ||
}) | ||
test('gee', function(done) { | ||
done = after(2, done) | ||
function cb(err) { | ||
assert.equal(err.message, 1); | ||
done() | ||
} | ||
var next = after(3, cb, function(err) { | ||
assert.equal(err.message, 2) | ||
done() | ||
}); | ||
suite("after", function () { | ||
test("after when called with 0 invokes", function (done) { | ||
after(0, done) | ||
}); | ||
next() | ||
next(new Error(1)) | ||
next(new Error(2)) | ||
}) | ||
test("after 1", function (done) { | ||
var next = after(1, call(done)) | ||
next() | ||
}) | ||
test('eee', function(done) { | ||
done = after(3, done) | ||
test("after 5", function (done) { | ||
var next = after(5, call(done)) | ||
, i = 5 | ||
function cb(err) { | ||
assert.equal(err.message, 1); | ||
done() | ||
} | ||
while (i--) { | ||
next() | ||
} | ||
}) | ||
var next = after(3, cb, function(err) { | ||
assert.equal(err.message, 2) | ||
done() | ||
}); | ||
test("manipulate count", function (done) { | ||
var next = after(1, call(done)) | ||
, i = 5 | ||
next(new Error(1)) | ||
next(new Error(2)) | ||
next(new Error(2)) | ||
}) | ||
next.count = i | ||
while (i--) { | ||
next() | ||
} | ||
}) | ||
test('gge', function(done) { | ||
function cb(err) { | ||
assert.equal(err.message, 1); | ||
done() | ||
} | ||
test("after terminates on error", function (done) { | ||
var next = after(2, call(done)) | ||
var next = after(3, cb, function(err) { | ||
// should not happen | ||
assert.ok(false); | ||
}); | ||
next({}) | ||
}) | ||
}) | ||
next() | ||
next() | ||
next(new Error(1)) | ||
}) | ||
function call(f) { | ||
return function () { | ||
f() | ||
test('egg', function(done) { | ||
function cb(err) { | ||
assert.equal(err.message, 1); | ||
done() | ||
} | ||
} | ||
var next = after(3, cb, function(err) { | ||
// should not happen | ||
assert.ok(false); | ||
}); | ||
next(new Error(1)) | ||
next() | ||
next() | ||
}) | ||
test('throws on too many calls', function(done) { | ||
var next = after(1, done); | ||
next() | ||
assert.throws(next, /after called too many times/); | ||
}); | ||
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
6281
115
76
0
7