[Pkg-javascript-commits] [node-pend] 02/04: Imported Upstream 1.2.0

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sat May 16 20:13:28 UTC 2015


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 4ced197f4c74c1a103bc9462871c7e193c940eb0
Author: Andrew Kelley <superjoe30 at gmail.com>
Date:   Sat May 16 20:09:25 2015 +0000

    Imported Upstream 1.2.0
---
 README.md    |  1 +
 index.js     | 12 ++++++++++--
 package.json |  6 +++---
 test.js      | 13 +++++++++++++
 4 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 5250960..bb40a07 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,7 @@ Dead-simple optimistic async helper.
 var Pend = require('pend');
 var pend = new Pend();
 pend.max = 10; // defaults to Infinity
+setTimeout(pend.hold(), 1000); // pend.wait will have to wait for this hold to finish
 pend.go(function(cb) {
   console.log("this function is immediately executed");
   setTimeout(function() {
diff --git a/index.js b/index.js
index e043b5b..3bf485e 100644
--- a/index.js
+++ b/index.js
@@ -24,10 +24,14 @@ Pend.prototype.wait = function(cb) {
   }
 };
 
-function pendGo(self, fn) {
+Pend.prototype.hold = function() {
+  return pendHold(this);
+};
+
+function pendHold(self) {
   self.pending += 1;
   var called = false;
-  fn(onCb);
+  return onCb;
   function onCb(err) {
     if (called) throw new Error("callback called twice");
     called = true;
@@ -45,3 +49,7 @@ function pendGo(self, fn) {
     listener(self.error);
   }
 }
+
+function pendGo(self, fn) {
+  fn(pendHold(self));
+}
diff --git a/package.json b/package.json
index ab5bb7a..8181f8b 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "pend",
-  "version": "1.1.3",
+  "version": "1.2.0",
   "description": "dead-simple optimistic async helper",
   "main": "index.js",
   "scripts": {
@@ -10,9 +10,9 @@
   "license": "MIT",
   "repository": {
     "type": "git",
-    "url": "git://github.com/superjoe30/node-pend.git"
+    "url": "git://github.com/andrewrk/node-pend.git"
   },
   "bugs": {
-    "url": "https://github.com/superjoe30/node-pend/issues"
+    "url": "https://github.com/andrewrk/node-pend/issues"
   }
 }
diff --git a/test.js b/test.js
index f2c7c5d..75c0f2a 100644
--- a/test.js
+++ b/test.js
@@ -18,6 +18,10 @@ var tests = [
     name: "calling wait twice",
     fn: testCallingWaitTwice,
   },
+  {
+    name: "hold()",
+    fn: testHoldFn,
+  },
 ];
 var testCount = tests.length;
 
@@ -122,3 +126,12 @@ function testCallingWaitTwice(cb) {
     pend.wait(cb);
   });
 }
+
+function testHoldFn(cb) {
+  var pend = new Pend();
+  setTimeout(pend.hold(), 100);
+  pend.go(function(cb) {
+    cb();
+  });
+  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