[Pkg-javascript-commits] [node-pend] 01/01: Imported Upstream version 1.1.3
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Tue Sep 9 17:40:24 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to annotated tag upstream/1.1.3
in repository node-pend.
commit 8be93e16b08c7b16c231cc10a4c107369b377b09
Author: Andrew Kelley <superjoe30 at gmail.com>
Date: Tue Sep 9 17:33:02 2014 +0000
Imported Upstream version 1.1.3
---
LICENSE | 23 +++++++++++++++++++++
index.js | 3 ++-
package.json | 2 +-
test.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------
4 files changed, 86 insertions(+), 8 deletions(-)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..0bbb53e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,23 @@
+The MIT License (Expat)
+
+Copyright (c) 2014 Andrew Kelley
+
+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.
diff --git a/index.js b/index.js
index 317993b..e043b5b 100644
--- a/index.js
+++ b/index.js
@@ -36,8 +36,9 @@ function pendGo(self, fn) {
if (self.waiting.length > 0 && self.pending < self.max) {
pendGo(self, self.waiting.shift());
} else if (self.pending === 0) {
- self.listeners.forEach(cbListener);
+ var listeners = self.listeners;
self.listeners = [];
+ listeners.forEach(cbListener);
}
}
function cbListener(listener) {
diff --git a/package.json b/package.json
index 44264cb..ab5bb7a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "pend",
- "version": "1.1.1",
+ "version": "1.1.3",
"description": "dead-simple optimistic async helper",
"main": "index.js",
"scripts": {
diff --git a/test.js b/test.js
index 7f5f5a0..f2c7c5d 100644
--- a/test.js
+++ b/test.js
@@ -1,9 +1,42 @@
var assert = require('assert');
var Pend = require('./');
-testBasic();
+var tests = [
+ {
+ name: "basic",
+ fn: testBasic,
+ },
+ {
+ name: "max",
+ fn: testWithMax,
+ },
+ {
+ name: "callback twice",
+ fn: testCallbackTwice,
+ },
+ {
+ name: "calling wait twice",
+ fn: testCallingWaitTwice,
+ },
+];
+var testCount = tests.length;
-function testBasic() {
+doOneTest();
+
+function doOneTest() {
+ var test = tests.shift();
+ if (!test) {
+ console.log(testCount + " tests passed.");
+ return;
+ }
+ process.stdout.write(test.name + "...");
+ test.fn(function() {
+ process.stdout.write("OK\n");
+ doOneTest();
+ });
+}
+
+function testBasic(cb) {
var pend = new Pend();
var results = [];
pend.go(function(cb) {
@@ -22,12 +55,12 @@ function testBasic() {
});
pend.wait(function(err) {
assert.deepEqual(results, [1,2,3,4]);
- testWithMax();
+ cb();
});
assert.deepEqual(results, [1, 2]);
}
-function testWithMax() {
+function testWithMax(cb) {
var pend = new Pend();
var results = [];
pend.max = 2;
@@ -54,17 +87,38 @@ function testWithMax() {
});
pend.wait(function(err) {
assert.deepEqual(results, ['a', 'b', 1, 'c', 1, 2]);
- testCallbackTwice();
+ cb();
});
assert.deepEqual(results, ['a', 'b']);
}
-function testCallbackTwice() {
+function testCallbackTwice(cb) {
var pend = new Pend();
pend.go(function(cb) {
+ setTimeout(cb, 100);
});
pend.go(function(cb) {
cb();
assert.throws(cb, /callback called twice/);
});
+ pend.wait(cb);
+}
+
+function testCallingWaitTwice(cb) {
+ var pend = new Pend();
+ pend.go(function(cb) {
+ setTimeout(cb, 100);
+ });
+ pend.wait(function() {
+ pend.go(function(cb) {
+ setTimeout(cb, 50);
+ });
+ pend.go(function(cb) {
+ setTimeout(cb, 10);
+ });
+ pend.go(function(cb) {
+ setTimeout(cb, 20);
+ });
+ pend.wait(cb);
+ });
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-pend.git
More information about the Pkg-javascript-commits
mailing list