diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-10-02 04:16:41 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-10-02 04:16:41 +0400 |
commit | 00ef58025a1f52dfabf2c4dc3898621d16a6e062 (patch) | |
tree | 76e9902eb094c8dcff8ececb6926cadb8601d9e3 | |
parent | e8dc53353798733df5fac96385ffa0aa3e5b908a (diff) |
inflight@1.0.3
We really, really, really don't want any race conditions in npm.
-rw-r--r-- | node_modules/inflight/inflight.js | 26 | ||||
-rw-r--r-- | node_modules/inflight/package.json | 32 | ||||
-rw-r--r-- | node_modules/inflight/test.js | 42 | ||||
-rw-r--r-- | node_modules/wrappy/LICENSE (renamed from node_modules/dezalgo/node_modules/wrappy/LICENSE) | 0 | ||||
-rw-r--r-- | node_modules/wrappy/README.md (renamed from node_modules/dezalgo/node_modules/wrappy/README.md) | 0 | ||||
-rw-r--r-- | node_modules/wrappy/package.json (renamed from node_modules/dezalgo/node_modules/wrappy/package.json) | 2 | ||||
-rw-r--r-- | node_modules/wrappy/test/basic.js (renamed from node_modules/dezalgo/node_modules/wrappy/test/basic.js) | 0 | ||||
-rw-r--r-- | node_modules/wrappy/wrappy.js (renamed from node_modules/dezalgo/node_modules/wrappy/wrappy.js) | 0 | ||||
-rw-r--r-- | package.json | 2 |
9 files changed, 70 insertions, 34 deletions
diff --git a/node_modules/inflight/inflight.js b/node_modules/inflight/inflight.js index 1fe279f9a..eeaf43491 100644 --- a/node_modules/inflight/inflight.js +++ b/node_modules/inflight/inflight.js @@ -1,8 +1,9 @@ -module.exports = inflight - +var wrappy = require('wrappy') var reqs = Object.create(null) var once = require('once') +module.exports = wrappy(inflight) + function inflight (key, cb) { if (reqs[key]) { reqs[key].push(cb) @@ -14,12 +15,19 @@ function inflight (key, cb) { } function makeres(key) { - return once(res) - function res(error, data) { + return once(function RES (error, data) { var cbs = reqs[key] - delete reqs[key] - cbs.forEach(function(cb) { - cb(error, data) - }) - } + var len = cbs.length + for (var i = 0; i < len; i++) { + cbs[i](error, data) + } + if (cbs.length > len) { + // added more in the interim. + // de-zalgo, just in case, but don't call again. + cbs.splice(0, len) + process.nextTick(RES.bind(this, error, data)) + } else { + delete reqs[key] + } + }) } diff --git a/node_modules/inflight/package.json b/node_modules/inflight/package.json index f4e294aad..9dabaaa9f 100644 --- a/node_modules/inflight/package.json +++ b/node_modules/inflight/package.json @@ -1,10 +1,11 @@ { "name": "inflight", - "version": "1.0.1", + "version": "1.0.3", "description": "Add callbacks to requests in flight to avoid async duplication", "main": "inflight.js", "dependencies": { - "once": "^1.3.0" + "once": "^1.3.0", + "wrappy": "1" }, "devDependencies": { "tap": "^0.4.10" @@ -26,25 +27,10 @@ }, "homepage": "https://github.com/isaacs/inflight", "license": "ISC", - "_id": "inflight@1.0.1", - "_shasum": "01f6911821535243c790ac0f998f54e9023ffb6f", - "_from": "inflight@~1.0.1", - "_npmVersion": "1.4.9", - "_npmUser": { - "name": "isaacs", - "email": "i@izs.me" - }, - "maintainers": [ - { - "name": "isaacs", - "email": "i@izs.me" - } - ], - "dist": { - "shasum": "01f6911821535243c790ac0f998f54e9023ffb6f", - "tarball": "http://registry.npmjs.org/inflight/-/inflight-1.0.1.tgz" - }, - "directories": {}, - "_resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.1.tgz", - "readme": "ERROR: No README data found!" + "readme": "# inflight\n\nAdd callbacks to requests in flight to avoid async duplication\n\n## USAGE\n\n```javascript\nvar inflight = require('inflight')\n\n// some request that does some stuff\nfunction req(key, callback) {\n // key is any random string. like a url or filename or whatever.\n //\n // will return either a falsey value, indicating that the\n // request for this key is already in flight, or a new callback\n // which when called will call all callbacks passed to inflightk\n // with the same key\n callback = inflight(key, callback)\n\n // If we got a falsey value back, then there's already a req going\n if (!callback) return\n\n // this is where you'd fetch the url or whatever\n // callback is also once()-ified, so it can safely be assigned\n // to multiple events etc. First call wins.\n setTimeout(function() {\n callback(null, key)\n }, 100)\n}\n\n// only assigns a single setTimeout\n// when it dings, all cbs get called\nreq('foo', cb1)\nreq('foo', cb2)\nreq('foo', cb3)\nreq('foo', cb4)\n```\n", + "readmeFilename": "README.md", + "gitHead": "a10cb02457ed415c9019d185902ec3db85b03984", + "_id": "inflight@1.0.3", + "_shasum": "70374be8ef3316248f37fa81276b6b329b95ff49", + "_from": "inflight@>=1.0.3 <1.1.0" } diff --git a/node_modules/inflight/test.js b/node_modules/inflight/test.js index 28fc14503..402d54205 100644 --- a/node_modules/inflight/test.js +++ b/node_modules/inflight/test.js @@ -31,3 +31,45 @@ test('basic', function (t) { t.notOk(b, 'second should get falsey inflight response') }) + +test('timing', function (t) { + var expect = [ + 'method one', + 'start one', + 'end one', + 'two', + 'tick', + 'three' + ] + var i = 0 + + function log (m) { + t.equal(m, expect[i], m + ' === ' + expect[i]) + ++i + if (i === expect.length) + t.end() + } + + function method (name, cb) { + log('method ' + name) + process.nextTick(cb) + } + + var one = inf('foo', function () { + log('start one') + var three = inf('foo', function () { + log('three') + }) + if (three) method('three', three) + log('end one') + }) + + method('one', one) + + var two = inf('foo', function () { + log('two') + }) + if (two) method('one', two) + + process.nextTick(log.bind(null, 'tick')) +}) diff --git a/node_modules/dezalgo/node_modules/wrappy/LICENSE b/node_modules/wrappy/LICENSE index 19129e315..19129e315 100644 --- a/node_modules/dezalgo/node_modules/wrappy/LICENSE +++ b/node_modules/wrappy/LICENSE diff --git a/node_modules/dezalgo/node_modules/wrappy/README.md b/node_modules/wrappy/README.md index 98eab2522..98eab2522 100644 --- a/node_modules/dezalgo/node_modules/wrappy/README.md +++ b/node_modules/wrappy/README.md diff --git a/node_modules/dezalgo/node_modules/wrappy/package.json b/node_modules/wrappy/package.json index 8145dc8c4..b88e66283 100644 --- a/node_modules/dezalgo/node_modules/wrappy/package.json +++ b/node_modules/wrappy/package.json @@ -30,7 +30,7 @@ "gitHead": "006a8cbac6b99988315834c207896eed71fd069a", "_id": "wrappy@1.0.1", "_shasum": "1e65969965ccbc2db4548c6b84a6f2c5aedd4739", - "_from": "wrappy@>=1.0.0 <2.0.0", + "_from": "wrappy@1.0.1", "_npmVersion": "2.0.0", "_nodeVersion": "0.10.31", "_npmUser": { diff --git a/node_modules/dezalgo/node_modules/wrappy/test/basic.js b/node_modules/wrappy/test/basic.js index 5ed0fcdfd..5ed0fcdfd 100644 --- a/node_modules/dezalgo/node_modules/wrappy/test/basic.js +++ b/node_modules/wrappy/test/basic.js diff --git a/node_modules/dezalgo/node_modules/wrappy/wrappy.js b/node_modules/wrappy/wrappy.js index bb7e7d6fc..bb7e7d6fc 100644 --- a/node_modules/dezalgo/node_modules/wrappy/wrappy.js +++ b/node_modules/wrappy/wrappy.js diff --git a/package.json b/package.json index 587916e39..1e6cb3c8d 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "github-url-from-username-repo": "~1.0.2", "glob": "~4.0.5", "graceful-fs": "~3.0.0", - "inflight": "~1.0.1", + "inflight": "~1.0.3", "inherits": "~2.0.1", "ini": "~1.2.0", "init-package-json": "~1.1.0", |