Browse Source

upgrade nthen to add back abort

Caleb James DeLisle 6 years ago
parent
commit
2581894541
3 changed files with 43 additions and 25 deletions
  1. 24 6
      node_modules/nthen/index.js
  2. 18 18
      node_modules/nthen/package.json
  3. 1 1
      package.json

+ 24 - 6
node_modules/nthen/index.js

@@ -11,7 +11,9 @@ type Nthen_t = ((WaitFor_t)=>void)=>NthenRet_t;
 module.exports = */ (function() {
 var nThen /*:Nthen_t*/ = function(next) {
     var funcs /*:Array<(WaitFor_t)=>void>*/ = [];
+    var timeouts = [];
     var calls = 0;
+    var abort;
     var waitFor = function(func) {
         calls++;
         return function() {
@@ -19,21 +21,28 @@ var nThen /*:Nthen_t*/ = function(next) {
                 func.apply(null, arguments);
             }
             calls = (calls || 1) - 1;
-            while (!calls && funcs.length) {
+            while (!calls && funcs.length && !abort) {
                 funcs.shift()(waitFor);
             }
         };
     };
+    waitFor.abort = function () {
+        timeouts.forEach(clearTimeout);
+        abort = 1;
+    };
     var ret = {
         nThen: function(next) {
-            if (!calls) {
-                next(waitFor);
-            } else {
-                funcs.push(next);
+            if (!abort) {
+                if (!calls) {
+                    next(waitFor);
+                } else {
+                    funcs.push(next);
+                }
             }
             return ret;
         },
         orTimeout: function(func, milliseconds) {
+            if (abort) { return ret; }
             if (!milliseconds) { throw Error("Must specify milliseconds to orTimeout()"); }
             var cto;
             var timeout = setTimeout(function() {
@@ -42,7 +51,16 @@ var nThen /*:Nthen_t*/ = function(next) {
                 calls = (calls || 1) - 1;
                 while (!calls && funcs.length) { funcs.shift()(waitFor); }
             }, milliseconds);
-            funcs.push(cto = function() { clearTimeout(timeout); });
+            funcs.push(cto = function() {
+                var idx = timeouts.indexOf(timeout);
+                if (idx > -1) {
+                    timeouts.splice(idx, 1);
+                    clearTimeout(timeout);
+                    return;
+                }
+                throw new Error('timeout not listed in array');
+            });
+            timeouts.push(timeout);
             return ret;
         }
     };

+ 18 - 18
node_modules/nthen/package.json

@@ -2,26 +2,26 @@
   "_args": [
     [
       {
-        "raw": "nthen@~0.1.1",
+        "raw": "nthen@0.1.7",
         "scope": null,
         "escapedName": "nthen",
         "name": "nthen",
-        "rawSpec": "~0.1.1",
-        "spec": ">=0.1.1 <0.2.0",
-        "type": "range"
+        "rawSpec": "0.1.7",
+        "spec": "0.1.7",
+        "type": "version"
       },
       "/Users/user/wrk/cjdns"
     ]
   ],
-  "_from": "nthen@>=0.1.1 <0.2.0",
-  "_id": "nthen@0.1.6",
+  "_from": "nthen@0.1.7",
+  "_id": "nthen@0.1.7",
   "_inCache": true,
   "_installable": true,
   "_location": "/nthen",
   "_nodeVersion": "6.5.0",
   "_npmOperationalInternal": {
     "host": "s3://npm-registry-packages",
-    "tmp": "tmp/nthen-0.1.6.tgz_1515110731303_0.6293239688966423"
+    "tmp": "tmp/nthen-0.1.7.tgz_1515574478951_0.00968303787522018"
   },
   "_npmUser": {
     "name": "cjd",
@@ -30,22 +30,22 @@
   "_npmVersion": "3.10.3",
   "_phantomChildren": {},
   "_requested": {
-    "raw": "nthen@~0.1.1",
+    "raw": "nthen@0.1.7",
     "scope": null,
     "escapedName": "nthen",
     "name": "nthen",
-    "rawSpec": "~0.1.1",
-    "spec": ">=0.1.1 <0.2.0",
-    "type": "range"
+    "rawSpec": "0.1.7",
+    "spec": "0.1.7",
+    "type": "version"
   },
   "_requiredBy": [
     "#USER",
     "/"
   ],
-  "_resolved": "https://registry.npmjs.org/nthen/-/nthen-0.1.6.tgz",
-  "_shasum": "bf6c2f1b8df98f65600d50d9795d0f8f35d7bf76",
+  "_resolved": "https://registry.npmjs.org/nthen/-/nthen-0.1.7.tgz",
+  "_shasum": "6b6a0586cd584383c35653bae737b6fdd2739d86",
   "_shrinkwrap": null,
-  "_spec": "nthen@~0.1.1",
+  "_spec": "nthen@0.1.7",
   "_where": "/Users/user/wrk/cjdns",
   "author": {
     "name": "Caleb James DeLisle"
@@ -62,10 +62,10 @@
   },
   "directories": {},
   "dist": {
-    "shasum": "bf6c2f1b8df98f65600d50d9795d0f8f35d7bf76",
-    "tarball": "https://registry.npmjs.org/nthen/-/nthen-0.1.6.tgz"
+    "shasum": "6b6a0586cd584383c35653bae737b6fdd2739d86",
+    "tarball": "https://registry.npmjs.org/nthen/-/nthen-0.1.7.tgz"
   },
-  "gitHead": "81ffaf218e267d9c6e7dafb363724222ab55e247",
+  "gitHead": "97381ded3517f90e29f3cc2cebf3a38840cb11a9",
   "homepage": "https://github.com/cjdelisle/nthen#readme",
   "keywords": [
     "async",
@@ -91,5 +91,5 @@
     "lint": "jshint --config .jshintrc --exclude-path .jshintignore .",
     "test": "tap ./test"
   },
-  "version": "0.1.6"
+  "version": "0.1.7"
 }

+ 1 - 1
package.json

@@ -2,7 +2,7 @@
     "name": "cjdns",
     "version": "0.17.2",
     "dependencies": {
-        "nthen": "~0.1.1",
+        "nthen": "~0.1.7",
         "jshint": "2.4.1"
     }
 }