Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclaudiahdz <cghr1990@gmail.com>2020-02-19 00:38:25 +0300
committerisaacs <i@izs.me>2020-05-08 04:11:51 +0300
commit09dac89c1bc20eb2c1f1f272c9e07fc1a579d75a (patch)
tree64335e20df7d982ec16b9c4e57a86182de0583af /node_modules/promise-call-limit
parentd594d8e55241a7a8abf7a61c97fc41c75fc9267f (diff)
@npmcli/arborist@0.0.0-pre.7
Diffstat (limited to 'node_modules/promise-call-limit')
-rw-r--r--node_modules/promise-call-limit/LICENSE15
-rw-r--r--node_modules/promise-call-limit/README.md30
-rw-r--r--node_modules/promise-call-limit/index.js43
-rw-r--r--node_modules/promise-call-limit/package.json62
4 files changed, 150 insertions, 0 deletions
diff --git a/node_modules/promise-call-limit/LICENSE b/node_modules/promise-call-limit/LICENSE
new file mode 100644
index 000000000..05eeeb88c
--- /dev/null
+++ b/node_modules/promise-call-limit/LICENSE
@@ -0,0 +1,15 @@
+The ISC License
+
+Copyright (c) Isaac Z. Schlueter
+
+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/promise-call-limit/README.md b/node_modules/promise-call-limit/README.md
new file mode 100644
index 000000000..eae5de8ce
--- /dev/null
+++ b/node_modules/promise-call-limit/README.md
@@ -0,0 +1,30 @@
+# promise-call-limit
+
+Call an array of promise-returning functions, restricting concurrency to a
+specified limit.
+
+## USAGE
+
+```js
+const promiseCallLimit = require('promise-call-limit')
+const things = getLongListOfThingsToFrobulate()
+
+// frobulate no more than 4 things in parallel
+promiseCallLimit(things.map(thing => () => frobulateThing(thing)), 4)
+ .then(results => console.log('frobulated 4 at a time', results))
+```
+
+## API
+
+### promiseCallLimit(queue Array<() => Promise>, limit = defaultLimit)
+
+The default limit is the number of CPUs on the system - 1, or 1.
+
+The reason for subtracting one is that presumably the main thread is taking
+up a CPU as well, so let's not be greedy.
+
+Note that the array should be a list of Promise-_returning_ functions, not
+Promises themselves. If you have a bunch of Promises already, you're best
+off just calling `Promise.all()`.
+
+The functions in the queue are called without any arguments.
diff --git a/node_modules/promise-call-limit/index.js b/node_modules/promise-call-limit/index.js
new file mode 100644
index 000000000..a093c2481
--- /dev/null
+++ b/node_modules/promise-call-limit/index.js
@@ -0,0 +1,43 @@
+const defLimit = require('os').cpus().length
+const callLimit = (queue, limit = defLimit) => new Promise((res, rej) => {
+ let active = 0
+ let current = 0
+ const results = []
+
+ let rejected = false
+ const reject = er => {
+ if (rejected)
+ return
+ rejected = true
+ rej(er)
+ }
+
+ let resolved = false
+ const resolve = () => {
+ if (resolved || active > 0)
+ return
+ resolved = true
+ res(results)
+ }
+
+ const run = () => {
+ const c = current++
+ if (c >= queue.length) {
+ return resolve()
+ }
+
+ active ++
+ results[c] = queue[c]().then(result => {
+ active --
+ results[c] = result
+ run()
+ return result
+ }, reject)
+ }
+
+ for (let i = 0; i < limit; i++) {
+ run()
+ }
+})
+
+module.exports = callLimit
diff --git a/node_modules/promise-call-limit/package.json b/node_modules/promise-call-limit/package.json
new file mode 100644
index 000000000..d3a16b116
--- /dev/null
+++ b/node_modules/promise-call-limit/package.json
@@ -0,0 +1,62 @@
+{
+ "_from": "promise-call-limit@^1.0.1",
+ "_id": "promise-call-limit@1.0.1",
+ "_inBundle": false,
+ "_integrity": "sha512-3+hgaa19jzCGLuSCbieeRsu5C2joKfYn8pY6JAuXFRVfF4IO+L7UPpFWNTeWT9pM7uhskvbPPd/oEOktCn317Q==",
+ "_location": "/promise-call-limit",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "promise-call-limit@^1.0.1",
+ "name": "promise-call-limit",
+ "escapedName": "promise-call-limit",
+ "rawSpec": "^1.0.1",
+ "saveSpec": null,
+ "fetchSpec": "^1.0.1"
+ },
+ "_requiredBy": [
+ "/@npmcli/arborist"
+ ],
+ "_resolved": "https://registry.npmjs.org/promise-call-limit/-/promise-call-limit-1.0.1.tgz",
+ "_shasum": "4bdee03aeb85674385ca934da7114e9bcd3c6e24",
+ "_spec": "promise-call-limit@^1.0.1",
+ "_where": "/Users/claudiahdz/npm/cli/node_modules/@npmcli/arborist",
+ "author": {
+ "name": "Isaac Z. Schlueter",
+ "email": "i@izs.me",
+ "url": "https://izs.me"
+ },
+ "bugs": {
+ "url": "https://github.com/isaacs/promise-call-limit/issues"
+ },
+ "bundleDependencies": false,
+ "deprecated": false,
+ "description": "Call an array of promise-returning functions, restricting concurrency to a specified limit.",
+ "devDependencies": {
+ "tap": "^14.10.6"
+ },
+ "files": [
+ "index.js"
+ ],
+ "funding": {
+ "url": "https://github.com/sponsors/isaacs"
+ },
+ "homepage": "https://github.com/isaacs/promise-call-limit#readme",
+ "license": "ISC",
+ "name": "promise-call-limit",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/isaacs/promise-call-limit.git"
+ },
+ "scripts": {
+ "postversion": "npm publish",
+ "prepublishOnly": "git push origin --follow-tags",
+ "preversion": "npm test",
+ "test": "tap"
+ },
+ "tap": {
+ "check-coverage": true
+ },
+ "version": "1.0.1"
+}