[Pkg-javascript-commits] [node-pend] 05/07: Imported Upstream version 1.1.3

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Tue Sep 9 17:38:27 UTC 2014


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

andrewrk-guest pushed a commit to branch master
in repository node-pend.

commit 202b0f4d29d957394066192628a2c3453eb45a3b
Author: Andrew Kelley <superjoe30 at gmail.com>
Date:   Tue Sep 9 17:33:02 2014 +0000

    Imported Upstream version 1.1.3
---
 LICENSE      |  4 ++--
 index.js     |  3 ++-
 package.json |  2 +-
 test.js      | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 4 files changed, 65 insertions(+), 10 deletions(-)

diff --git a/LICENSE b/LICENSE
index 044d34a..0bbb53e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
-Expat
+The MIT License (Expat)
 
-Copyright (c) 2013 Andrew Kelley
+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
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 7f12237..ab5bb7a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "pend",
-  "version": "1.1.2",
+  "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