Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

p-limit

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-limit - npm Package Compare versions

Comparing version 6.1.0 to 6.2.0

38

index.d.ts

@@ -44,1 +44,39 @@ export type LimitFunction = {

export default function pLimit(concurrency: number): LimitFunction;
export type Options = {
/**
Concurrency limit.
Minimum: `1`.
*/
readonly concurrency: number;
};
/**
Returns a function with limited concurrency.
The returned function manages its own concurrent executions, allowing you to call it multiple times without exceeding the specified concurrency limit.
Ideal for scenarios where you need to control the number of simultaneous executions of a single function, rather than managing concurrency across multiple functions.
@param function_ - Promise-returning/async function.
@return Function with limited concurrency.
@example
```
import {limitFunction} from 'p-limit';
const limitedFunction = limitFunction(async () => {
return doSomething();
}, {concurrency: 1});
const input = Array.from({length: 10}, limitedFunction);
// Only one promise is run at once.
await Promise.all(input);
```
*/
export function limitFunction<Arguments extends unknown[], ReturnType>(
function_: (...arguments_: Arguments) => PromiseLike<ReturnType> | ReturnType,
option: Options
): (...arguments_: Arguments) => Promise<ReturnType>;

@@ -93,2 +93,9 @@ import Queue from 'yocto-queue';

export function limitFunction(function_, option) {
const {concurrency} = option;
const limit = pLimit(concurrency);
return (...arguments_) => limit(() => function_(...arguments_));
}
function validateConcurrency(concurrency) {

@@ -95,0 +102,0 @@ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {

2

package.json
{
"name": "p-limit",
"version": "6.1.0",
"version": "6.2.0",
"description": "Run multiple promise-returning & async functions with limited concurrency",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -33,3 +33,3 @@ # p-limit

### pLimit(concurrency)
### pLimit(concurrency) <sup>default export</sup>

@@ -41,4 +41,3 @@ Returns a `limit` function.

Type: `number`\
Minimum: `1`\
Default: `Infinity`
Minimum: `1`

@@ -83,2 +82,40 @@ Concurrency limit.

### limitFunction(fn, options) <sup>named export</sup>
Returns a function with limited concurrency.
The returned function manages its own concurrent executions, allowing you to call it multiple times without exceeding the specified concurrency limit.
Ideal for scenarios where you need to control the number of simultaneous executions of a single function, rather than managing concurrency across multiple functions.
```js
import {limitFunction} from 'p-limit';
const limitedFunction = limitFunction(async () => {
return doSomething();
}, {concurrency: 1});
const input = Array.from({length: 10}, limitedFunction);
// Only one promise is run at once.
await Promise.all(input);
```
#### fn
Type: `Function`
Promise-returning/async function.
#### options
Type: `object`
#### concurrency
Type: `number`\
Minimum: `1`
Concurrency limit.
## FAQ

@@ -85,0 +122,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc