diff --git a/node_modules/call-limit/CHANGELOG.md b/node_modules/call-limit/CHANGELOG.md new file mode 100644 index 0000000000000..a6b1df978e11d --- /dev/null +++ b/node_modules/call-limit/CHANGELOG.md @@ -0,0 +1,16 @@ +# Changelog + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +### [1.1.1](https://github.com/iarna/call-limit/compare/v1.1.0...v1.1.1) (2019-06-03) + + +### Bug Fixes + +* **call-limit:** Limiter rewrite ([bbd0ea6](https://github.com/iarna/call-limit/commit/bbd0ea6)) +* **test:** Update tests to let/const ([f0b7f98](https://github.com/iarna/call-limit/commit/f0b7f98)) + + +### Tests + +* Test coverage for limited promise based methods ([d5069f4](https://github.com/iarna/call-limit/commit/d5069f4)) diff --git a/node_modules/call-limit/LICENSE b/node_modules/call-limit/LICENSE new file mode 100644 index 0000000000000..216e843abcbac --- /dev/null +++ b/node_modules/call-limit/LICENSE @@ -0,0 +1,13 @@ +Copyright Rebecca Turner + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/node_modules/call-limit/README.md b/node_modules/call-limit/README.md index 590ca419ee6cf..62086b68496f3 100644 --- a/node_modules/call-limit/README.md +++ b/node_modules/call-limit/README.md @@ -4,17 +4,17 @@ call-limit Limit the number of simultaneous executions of a async function. ```javascript -var fs = require('fs') -var limit = require('call-limit') -var limitedStat = limit(fs.stat, 5) +const fs = require('fs') +const limit = require('call-limit') +const limitedStat = limit(fs.stat, 5) ``` Or with promise returning functions: ```javascript -var fs = Bluebird.promisifyAll(require('fs')) -var limit = require('call-limit') -var limitedStat = limit.promise(fs.statAsync, 5) +const fs = Bluebird.promisifyAll(require('fs')) +const limit = require('call-limit') +const limitedStat = limit.promise(fs.statAsync, 5) ``` ### USAGE: @@ -22,7 +22,7 @@ var limitedStat = limit.promise(fs.statAsync, 5) Given that: ```javascript -var limit = require('call-limit') +const limit = require('call-limit') ``` ### limit(func, maxRunning) → limitedFunc diff --git a/node_modules/call-limit/call-limit.js b/node_modules/call-limit/call-limit.js index d6e4534b8a2e8..2dc7d279a3a52 100644 --- a/node_modules/call-limit/call-limit.js +++ b/node_modules/call-limit/call-limit.js @@ -1,86 +1,99 @@ -"use strict" +'use strict' -var defaultMaxRunning = 50 +const defaultMaxRunning = 50 -var limit = module.exports = function (func, maxRunning) { - var running = 0 - var queue = [] +const limit = module.exports = function (func, maxRunning) { + const state = {running: 0, queue: []} if (!maxRunning) maxRunning = defaultMaxRunning return function limited () { - var self = this - var args = Array.prototype.slice.call(arguments) - if (running >= maxRunning) { - queue.push({self: this, args: args}) - return + const args = Array.prototype.slice.call(arguments) + if (state.running >= maxRunning) { + state.queue.push({obj: this, args}) + } else { + callFunc(this, args) + } + } + function callNext () { + if (state.queue.length === 0) return + const next = state.queue.shift() + callFunc(next.obj, next.args) + } + function callFunc (obj, args) { + const cb = typeof args[args.length - 1] === 'function' && args.pop() + try { + ++state.running + func.apply(obj, args.concat(function () { + --state.running + process.nextTick(callNext) + if (cb) process.nextTick(() => cb.apply(obj, arguments)) + })) + } catch (err) { + --state.running + if (cb) process.nextTick(() => cb.call(obj, err)) + process.nextTick(callNext) } - var cb = typeof args[args.length-1] === 'function' && args.pop() - ++ running - args.push(function () { - var cbargs = arguments - -- running - cb && process.nextTick(function () { - cb.apply(self, cbargs) - }) - if (queue.length) { - var next = queue.shift() - limited.apply(next.self, next.args) - } - }) - func.apply(self, args) } } module.exports.method = function (classOrObj, method, maxRunning) { if (typeof classOrObj === 'function') { - var func = classOrObj.prototype[method] + const func = classOrObj.prototype[method] classOrObj.prototype[method] = limit(func, maxRunning) } else { - var func = classOrObj[method] + const func = classOrObj[method] classOrObj[method] = limit(func, maxRunning) } } module.exports.promise = function (func, maxRunning) { - var running = 0 - var queue = [] + const state = {running: 0, queue: []} if (!maxRunning) maxRunning = defaultMaxRunning - return function () { - var self = this - var args = Array.prototype.slice.call(arguments) - return new Promise(function (resolve) { - if (running >= maxRunning) { - queue.push({self: self, args: args, resolve: resolve}) - return - } else { - runNext(self, args, resolve) - } - function runNext (self, args, resolve) { - ++ running - resolve( - func.apply(self, args) - .then(finish, function (err) { - finish(err) - throw err - })) - } - - function finish () { - -- running - if (queue.length) { - var next = queue.shift() - process.nextTick(runNext, next.self, next.args, next.resolve) - } - } + return function limited () { + const args = Array.prototype.slice.call(arguments) + if (state.running >= maxRunning) { + return new Promise(resolve => { + state.queue.push({resolve, obj: this, args}) + }) + } else { + return callFunc(this, args) + } + } + function callNext () { + if (state.queue.length === 0) return + const next = state.queue.shift() + next.resolve(callFunc(next.obj, next.args)) + } + function callFunc (obj, args) { + return callFinally(() => { + ++state.running + return func.apply(obj, args) + }, () => { + --state.running + process.nextTick(callNext) }) } + function callFinally (action, fin) { + try { + return Promise.resolve(action()).then(value => { + fin() + return value + }, err => { + fin() + return Promise.reject(err) + }) + } catch (err) { + fin() + return Promise.reject(err) + } + } } module.exports.promise.method = function (classOrObj, method, maxRunning) { if (typeof classOrObj === 'function') { - var func = classOrObj.prototype[method] + const func = classOrObj.prototype[method] classOrObj.prototype[method] = limit.promise(func, maxRunning) } else { - var func = classOrObj[method] + const func = classOrObj[method] classOrObj[method] = limit.promise(func, maxRunning) } } diff --git a/node_modules/call-limit/package.json b/node_modules/call-limit/package.json index e074b244eb367..2e3b264de115b 100644 --- a/node_modules/call-limit/package.json +++ b/node_modules/call-limit/package.json @@ -1,32 +1,28 @@ { - "_args": [ - [ - "call-limit@1.1.0", - "/Users/rebecca/code/npm" - ] - ], - "_from": "call-limit@1.1.0", - "_id": "call-limit@1.1.0", + "_from": "call-limit@1.1.1", + "_id": "call-limit@1.1.1", "_inBundle": false, - "_integrity": "sha1-b9YbA/PaQqLNDsK2DwK9DnGZH+o=", + "_integrity": "sha512-5twvci5b9eRBw2wCfPtN0GmlR2/gadZqyFpPhOK6CvMFoFgA+USnZ6Jpu1lhG9h85pQ3Ouil3PfXWRD4EUaRiQ==", "_location": "/call-limit", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, - "raw": "call-limit@1.1.0", + "raw": "call-limit@1.1.1", "name": "call-limit", "escapedName": "call-limit", - "rawSpec": "1.1.0", + "rawSpec": "1.1.1", "saveSpec": null, - "fetchSpec": "1.1.0" + "fetchSpec": "1.1.1" }, "_requiredBy": [ + "#USER", "/" ], - "_resolved": "https://registry.npmjs.org/call-limit/-/call-limit-1.1.0.tgz", - "_spec": "1.1.0", - "_where": "/Users/rebecca/code/npm", + "_resolved": "https://registry.npmjs.org/call-limit/-/call-limit-1.1.1.tgz", + "_shasum": "ef15f2670db3f1992557e2d965abc459e6e358d4", + "_spec": "call-limit@1.1.1", + "_where": "/Users/isaacs/dev/npm/cli", "author": { "name": "Rebecca Turner", "email": "me@re-becca.org" @@ -34,10 +30,16 @@ "bugs": { "url": "https://github.com/iarna/call-limit/issues" }, + "bundleDependencies": false, "dependencies": {}, + "deprecated": false, "description": "Limit the number of simultaneous calls to an async function", "devDependencies": { - "tap": "^1.0.0" + "@iarna/standard": "*", + "standard-version": "*", + "tap": "^14.2.0", + "weallbehave": "*", + "weallcontribute": "*" }, "files": [ "call-limit.js" @@ -51,7 +53,13 @@ "url": "git+https://github.com/iarna/call-limit.git" }, "scripts": { - "test": "tap test/*.js" + "postrelease": "npm publish && git push --follow-tags", + "prerelease": "npm t", + "pretest": "iarna-standard", + "release": "standard-version -s", + "test": "tap test/*.js", + "update-coc": "weallbehave -o . && git add CODE_OF_CONDUCT.md && git commit -m 'docs(coc): updated CODE_OF_CONDUCT.md'", + "update-contrib": "weallcontribute -o . && git add CONTRIBUTING.md && git commit -m 'docs(contributing): updated CONTRIBUTING.md'" }, - "version": "1.1.0" + "version": "1.1.1" } diff --git a/package-lock.json b/package-lock.json index 7a050ce25c84c..0cc3bdeccf815 100644 --- a/package-lock.json +++ b/package-lock.json @@ -626,9 +626,9 @@ } }, "call-limit": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/call-limit/-/call-limit-1.1.0.tgz", - "integrity": "sha1-b9YbA/PaQqLNDsK2DwK9DnGZH+o=" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/call-limit/-/call-limit-1.1.1.tgz", + "integrity": "sha512-5twvci5b9eRBw2wCfPtN0GmlR2/gadZqyFpPhOK6CvMFoFgA+USnZ6Jpu1lhG9h85pQ3Ouil3PfXWRD4EUaRiQ==" }, "caller": { "version": "1.0.1", diff --git a/package.json b/package.json index 82745521766f8..18ed3b6f4c370 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "bluebird": "^3.5.5", "byte-size": "^5.0.1", "cacache": "^11.3.3", - "call-limit": "~1.1.0", + "call-limit": "^1.1.1", "chownr": "^1.1.1", "ci-info": "^2.0.0", "cli-columns": "^3.1.2",