Comparing version 6.0.0 to 6.1.0
@@ -13,2 +13,7 @@ export type LimitFunction = { | ||
/** | ||
Get or set the concurrency limit. | ||
*/ | ||
concurrency: number; | ||
/** | ||
Discard pending promises that are waiting to run. | ||
@@ -15,0 +20,0 @@ |
27
index.js
import Queue from 'yocto-queue'; | ||
export default function pLimit(concurrency) { | ||
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) { | ||
throw new TypeError('Expected `concurrency` to be a number from 1 and up'); | ||
} | ||
validateConcurrency(concurrency); | ||
@@ -12,3 +10,3 @@ const queue = new Queue(); | ||
const resumeNext = () => { | ||
if (queue.size > 0) { | ||
if (activeCount < concurrency && queue.size > 0) { | ||
queue.dequeue()(); | ||
@@ -76,2 +74,17 @@ // Since `pendingCount` has been decreased by one, increase `activeCount` by one. | ||
}, | ||
concurrency: { | ||
get: () => concurrency, | ||
set(newConcurrency) { | ||
validateConcurrency(newConcurrency); | ||
concurrency = newConcurrency; | ||
queueMicrotask(() => { | ||
// eslint-disable-next-line no-unmodified-loop-condition | ||
while (activeCount < concurrency && queue.size > 0) { | ||
resumeNext(); | ||
} | ||
}); | ||
}, | ||
}, | ||
}); | ||
@@ -81,1 +94,7 @@ | ||
} | ||
function validateConcurrency(concurrency) { | ||
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) { | ||
throw new TypeError('Expected `concurrency` to be a number from 1 and up'); | ||
} | ||
} |
{ | ||
"name": "p-limit", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "Run multiple promise-returning & async functions with limited concurrency", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -77,2 +77,6 @@ # p-limit | ||
### limit.concurrency | ||
Get or set the concurrency limit. | ||
## FAQ | ||
@@ -79,0 +83,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8230
114
93