Comparing version 2.3.0 to 3.0.0
@@ -29,3 +29,3 @@ export interface Limit { | ||
*/ | ||
clearQueue(): void; | ||
clearQueue: () => void; | ||
} | ||
@@ -32,0 +32,0 @@ |
28
index.js
@@ -20,5 +20,6 @@ 'use strict'; | ||
const run = (fn, resolve, ...args) => { | ||
const run = async (fn, resolve, ...args) => { | ||
activeCount++; | ||
// TODO: Get rid of `pTry`. It's not needed anymore. | ||
const result = pTry(fn, ...args); | ||
@@ -28,11 +29,23 @@ | ||
result.then(next, next); | ||
try { | ||
await result; | ||
} catch {} | ||
next(); | ||
}; | ||
const enqueue = (fn, resolve, ...args) => { | ||
if (activeCount < concurrency) { | ||
run(fn, resolve, ...args); | ||
} else { | ||
queue.push(run.bind(null, fn, resolve, ...args)); | ||
} | ||
queue.push(run.bind(null, fn, resolve, ...args)); | ||
(async () => { | ||
// This function needs to wait until the next microtask before comparing | ||
// `activeCount` to `concurrency`, because `activeCount` is updated asynchronously | ||
// when the run function is dequeued and called. The comparison in the if-statement | ||
// needs to happen asynchronously as well to get an up-to-date value for `activeCount`. | ||
await Promise.resolve(); | ||
if (activeCount < concurrency && queue.length > 0) { | ||
queue.shift()(); | ||
} | ||
})(); | ||
}; | ||
@@ -59,2 +72,1 @@ | ||
module.exports = pLimit; | ||
module.exports.default = pLimit; |
{ | ||
"name": "p-limit", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"description": "Run multiple promise-returning & async functions with limited concurrency", | ||
@@ -11,9 +11,9 @@ "license": "MIT", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
"test": "xo && ava && tsd" | ||
}, | ||
@@ -45,10 +45,10 @@ "files": [ | ||
"devDependencies": { | ||
"ava": "^1.2.1", | ||
"ava": "^2.4.0", | ||
"delay": "^4.1.0", | ||
"in-range": "^1.0.0", | ||
"random-int": "^1.0.0", | ||
"time-span": "^2.0.0", | ||
"tsd-check": "^0.3.0", | ||
"xo": "^0.24.0" | ||
"in-range": "^2.0.0", | ||
"random-int": "^2.0.1", | ||
"time-span": "^4.0.0", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.26.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# p-limit [![Build Status](https://travis-ci.org/sindresorhus/p-limit.svg?branch=master)](https://travis-ci.org/sindresorhus/p-limit) | ||
# p-limit [![Build Status](https://travis-ci.com/sindresorhus/p-limit.svg?branch=master)](https://travis-ci.com/github/sindresorhus/p-limit) | ||
@@ -3,0 +3,0 @@ > Run multiple promise-returning & async functions with limited concurrency |
Sorry, the diff of this file is not supported yet
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
7853
85