Comparing version 3.1.0 to 4.0.0
@@ -1,32 +0,32 @@ | ||
declare namespace pLimit { | ||
interface Limit { | ||
/** | ||
The number of promises that are currently running. | ||
*/ | ||
readonly activeCount: number; | ||
/* eslint-disable @typescript-eslint/member-ordering */ | ||
/** | ||
The number of promises that are waiting to run (i.e. their internal `fn` was not called yet). | ||
*/ | ||
readonly pendingCount: number; | ||
export interface LimitFunction { | ||
/** | ||
The number of promises that are currently running. | ||
*/ | ||
readonly activeCount: number; | ||
/** | ||
Discard pending promises that are waiting to run. | ||
/** | ||
The number of promises that are waiting to run (i.e. their internal `fn` was not called yet). | ||
*/ | ||
readonly pendingCount: number; | ||
This might be useful if you want to teardown the queue at the end of your program's lifecycle or discard any function calls referencing an intermediary state of your app. | ||
/** | ||
Discard pending promises that are waiting to run. | ||
Note: This does not cancel promises that are already running. | ||
*/ | ||
clearQueue: () => void; | ||
This might be useful if you want to teardown the queue at the end of your program's lifecycle or discard any function calls referencing an intermediary state of your app. | ||
/** | ||
@param fn - Promise-returning/async function. | ||
@param arguments - Any arguments to pass through to `fn`. Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a lot of functions. | ||
@returns The promise returned by calling `fn(...arguments)`. | ||
*/ | ||
<Arguments extends unknown[], ReturnType>( | ||
fn: (...arguments: Arguments) => PromiseLike<ReturnType> | ReturnType, | ||
...arguments: Arguments | ||
): Promise<ReturnType>; | ||
} | ||
Note: This does not cancel promises that are already running. | ||
*/ | ||
clearQueue: () => void; | ||
/** | ||
@param fn - Promise-returning/async function. | ||
@param arguments - Any arguments to pass through to `fn`. Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a lot of functions. | ||
@returns The promise returned by calling `fn(...arguments)`. | ||
*/ | ||
<Arguments extends unknown[], ReturnType>( | ||
fn: (...arguments: Arguments) => PromiseLike<ReturnType> | ReturnType, | ||
...arguments: Arguments | ||
): Promise<ReturnType>; | ||
} | ||
@@ -40,4 +40,2 @@ | ||
*/ | ||
declare function pLimit(concurrency: number): pLimit.Limit; | ||
export = pLimit; | ||
export default function pLimit(concurrency: number): LimitFunction; |
27
index.js
@@ -1,6 +0,5 @@ | ||
'use strict'; | ||
const Queue = require('yocto-queue'); | ||
import Queue from 'yocto-queue'; | ||
const pLimit = concurrency => { | ||
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) { | ||
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'); | ||
@@ -20,3 +19,3 @@ } | ||
const run = async (fn, resolve, ...args) => { | ||
const run = async (fn, resolve, args) => { | ||
activeCount++; | ||
@@ -35,4 +34,4 @@ | ||
const enqueue = (fn, resolve, ...args) => { | ||
queue.enqueue(run.bind(null, fn, resolve, ...args)); | ||
const enqueue = (fn, resolve, args) => { | ||
queue.enqueue(run.bind(undefined, fn, resolve, args)); | ||
@@ -53,3 +52,3 @@ (async () => { | ||
const generator = (fn, ...args) => new Promise(resolve => { | ||
enqueue(fn, resolve, ...args); | ||
enqueue(fn, resolve, args); | ||
}); | ||
@@ -59,6 +58,6 @@ | ||
activeCount: { | ||
get: () => activeCount | ||
get: () => activeCount, | ||
}, | ||
pendingCount: { | ||
get: () => queue.size | ||
get: () => queue.size, | ||
}, | ||
@@ -68,9 +67,7 @@ clearQueue: { | ||
queue.clear(); | ||
} | ||
} | ||
}, | ||
}, | ||
}); | ||
return generator; | ||
}; | ||
module.exports = pLimit; | ||
} |
{ | ||
"name": "p-limit", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Run multiple promise-returning & async functions with limited concurrency", | ||
@@ -13,4 +13,6 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -42,13 +44,13 @@ "scripts": { | ||
"dependencies": { | ||
"yocto-queue": "^0.1.0" | ||
"yocto-queue": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"delay": "^4.4.0", | ||
"in-range": "^2.0.0", | ||
"random-int": "^2.0.1", | ||
"time-span": "^4.0.0", | ||
"tsd": "^0.13.1", | ||
"xo": "^0.35.0" | ||
"ava": "^3.15.0", | ||
"delay": "^5.0.0", | ||
"in-range": "^3.0.0", | ||
"random-int": "^3.0.0", | ||
"time-span": "^5.0.0", | ||
"tsd": "^0.17.0", | ||
"xo": "^0.44.0" | ||
} | ||
} |
@@ -14,3 +14,3 @@ # p-limit | ||
```js | ||
const pLimit = require('p-limit'); | ||
import pLimit from 'p-limit'; | ||
@@ -25,7 +25,5 @@ const limit = pLimit(1); | ||
(async () => { | ||
// Only one promise is run at once | ||
const result = await Promise.all(input); | ||
console.log(result); | ||
})(); | ||
// Only one promise is run at once | ||
const result = await Promise.all(input); | ||
console.log(result); | ||
``` | ||
@@ -32,0 +30,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
7788
Yes
85
100
+ Addedyocto-queue@1.1.1(transitive)
- Removedyocto-queue@0.1.0(transitive)
Updatedyocto-queue@^1.0.0