[Pkg-javascript-commits] [node-async] 314/480: added forever
Jonas Smedegaard
js at moszumanska.debian.org
Fri May 2 08:58:37 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-async.
commit cce102df20916956f5ccad82b7da6019387e2fdc
Author: Caolan McMahon <caolan at caolanmcmahon.com>
Date: Fri Mar 15 12:48:13 2013 +0000
added forever
---
README.md | 9 +++++++++
lib/async.js | 13 +++++++++++++
test/test-async.js | 18 ++++++++++++++++++
3 files changed, 40 insertions(+)
diff --git a/README.md b/README.md
index 1716476..2c6e28b 100644
--- a/README.md
+++ b/README.md
@@ -91,6 +91,7 @@ So far its been tested in IE6, IE7, IE8, FF3.6 and Chrome 5. Usage:
* [doWhilst](#doWhilst)
* [until](#until)
* [doUntil](#doUntil)
+* [forever](#forever)
* [waterfall](#waterfall)
* [compose](#compose)
* [applyEach](#applyEach)
@@ -754,6 +755,14 @@ The inverse of async.whilst.
Like doWhilst except the test is inverted. Note the argument ordering differs from `until`.
+---------------------------------------
+
+<a name="forever" />
+### forever(fn, callback)
+
+Calls the asynchronous function 'fn' repeatedly, in series, indefinitely.
+If an error is passed to fn's callback then 'callback' is called with the
+error, otherwise it will never be called.
---------------------------------------
diff --git a/lib/async.js b/lib/async.js
index 98f2127..b5bfc4c 100755
--- a/lib/async.js
+++ b/lib/async.js
@@ -910,6 +910,19 @@
}
};
+ async.forever = function (fn, callback) {
+ function next(err) {
+ if (err) {
+ if (callback) {
+ return callback(err);
+ }
+ throw err;
+ }
+ fn(next);
+ }
+ next();
+ };
+
// AMD / RequireJS
if (typeof define !== 'undefined' && define.amd) {
define([], function () {
diff --git a/test/test-async.js b/test/test-async.js
index cba6f4b..f9b9c08 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -66,6 +66,24 @@ function getFunctionsObject(call_order) {
};
}
+exports['forever'] = function (test) {
+ test.expect(1);
+ var counter = 0;
+ function addOne(callback) {
+ counter++;
+ if (counter === 50) {
+ return callback('too big!');
+ }
+ async.setImmediate(function () {
+ callback();
+ });
+ }
+ async.forever(addOne, function (err) {
+ test.equal(err, 'too big!');
+ test.done();
+ });
+};
+
exports['applyEach'] = function (test) {
test.expect(4);
var call_order = [];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git
More information about the Pkg-javascript-commits
mailing list