[Pkg-javascript-commits] [node-after] 01/02: Imported Upstream version 0.8.1

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Sun Mar 29 16:52:39 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-after.

commit 63c05363933d0c5d27a710c821f8483ac0707ccb
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Sun Mar 29 18:24:13 2015 +0200

    Imported Upstream version 0.8.1
---
 .gitignore         |   2 +
 .travis.yml        |   5 +++
 LICENCE            |  19 +++++++++
 README.md          |  75 +++++++++++++++++++++++++++++++++
 index.js           |  28 +++++++++++++
 package.json       |  27 ++++++++++++
 test/after-test.js | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 276 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6c78602
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+node_modules
+.monitor
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..84fd7ca
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+  - 0.6
+  - 0.8
+  - 0.9
diff --git a/LICENCE b/LICENCE
new file mode 100644
index 0000000..7c35130
--- /dev/null
+++ b/LICENCE
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Raynos.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0012d35
--- /dev/null
+++ b/README.md
@@ -0,0 +1,75 @@
+# After [![Build Status][1]][2]
+
+Invoke callback after n calls
+
+## Status: production ready
+
+## Example
+
+    var after = require("after")
+        , next = after(3, logItWorks)
+
+    next()
+    next()
+    next() // it works
+
+    function logItWorks() {
+        console.log("it works!")
+    }
+
+## Example with error handling
+
+    var after = require("after")
+        , next = after(3, logError)
+
+    next()
+    next(new Error("oops")) // logs oops
+    next() // does nothing
+
+    function logError(err) {
+        console.log(err)
+    }
+
+## After < 0.6.0
+
+Older versions of after had iterators and flows in them.
+
+These have been replaced with seperate modules
+
+ - [iterators][8]
+ - [composite][9]
+
+## Installation
+
+`npm install after`
+
+## Tests
+
+`npm test`
+
+## Blog post
+
+ - [Flow control in node.js][3]
+
+## Examples :
+
+ - [Determining the end of asynchronous operations][4]
+ - [In javascript what are best practices for executing multiple asynchronous functions][5]
+ - [JavaScript performance long running tasks][6]
+ - [Synchronous database queries with node.js][7]
+
+## Contributors
+
+ - Raynos
+
+## MIT Licenced
+
+  [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
+  [4]: http://stackoverflow.com/questions/6852059/determining-the-end-of-asynchronous-operations-javascript/6852307#6852307
+  [5]: http://stackoverflow.com/questions/6869872/in-javascript-what-are-best-practices-for-executing-multiple-asynchronous-functi/6870031#6870031
+  [6]: http://stackoverflow.com/questions/6864397/javascript-performance-long-running-tasks/6889419#6889419
+  [7]: http://stackoverflow.com/questions/6597493/synchronous-database-queries-with-node-js/6620091#6620091
+  [8]: http://github.com/Raynos/iterators
+  [9]: http://github.com/Raynos/composite
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..ec24879
--- /dev/null
+++ b/index.js
@@ -0,0 +1,28 @@
+module.exports = after
+
+function after(count, callback, err_cb) {
+    var bail = false
+    err_cb = err_cb || noop
+    proxy.count = count
+
+    return (count === 0) ? callback() : proxy
+
+    function proxy(err, result) {
+        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) {
+            bail = true
+            callback(err)
+            // future error callbacks will go to error handler
+            callback = err_cb
+        } else if (proxy.count === 0 && !bail) {
+            callback(null, result)
+        }
+    }
+}
+
+function noop() {}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..2ee0785
--- /dev/null
+++ b/package.json
@@ -0,0 +1,27 @@
+{
+  "name": "after",
+  "description": "after - tiny flow control",
+  "version": "0.8.1",
+  "author": "Raynos <raynos2 at gmail.com>",
+  "contributors": [
+    {
+      "name": "Raynos",
+      "email": "raynos2 at 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"
+}
diff --git a/test/after-test.js b/test/after-test.js
new file mode 100644
index 0000000..0d63f4c
--- /dev/null
+++ b/test/after-test.js
@@ -0,0 +1,120 @@
+/*global suite, test*/
+
+var assert = require("assert")
+    , after = require("../")
+
+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()
+    });
+
+    next()
+    next(new Error(1))
+    next(new Error(2))
+})
+
+test('eee', function(done) {
+    done = after(3, done)
+
+    function cb(err) {
+        assert.equal(err.message, 1);
+        done()
+    }
+
+    var next = after(3, cb, function(err) {
+        assert.equal(err.message, 2)
+        done()
+    });
+
+    next(new Error(1))
+    next(new Error(2))
+    next(new Error(2))
+})
+
+test('gge', 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()
+    next()
+    next(new Error(1))
+})
+
+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/);
+});
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-after.git



More information about the Pkg-javascript-commits mailing list