Gathering detailed insights and metrics for p-throttle
Gathering detailed insights and metrics for p-throttle
Gathering detailed insights and metrics for p-throttle
Gathering detailed insights and metrics for p-throttle
npm install p-throttle
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.4
Supply Chain
99.5
Quality
82.6
Maintenance
100
Vulnerability
100
License
JavaScript (91.5%)
TypeScript (8.5%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
449 Stars
53 Commits
31 Forks
8 Watching
1 Branches
15 Contributors
Minified
Minified + Gzipped
Latest Version
7.0.0
Package Id
p-throttle@7.0.0
Unpacked Size
11.43 kB
Size
3.89 kB
File Count
5
NPM Version
10.9.0
Node Version
23.3.0
Publised On
30 Nov 2024
Cumulative downloads
Total Downloads
Last day
0%
0
Compared to previous day
Last week
0%
0
Compared to previous week
Last month
0%
0
Compared to previous month
Last year
0%
0
Compared to previous year
Throttle promise-returning & async functions
It also works with normal functions.
It rate-limits function calls without discarding them, making it ideal for external API interactions where avoiding call loss is crucial.
1npm install p-throttle
Here, the throttled function is only called twice a second:
1import pThrottle from 'p-throttle'; 2 3const now = Date.now(); 4 5const throttle = pThrottle({ 6 limit: 2, 7 interval: 1000 8}); 9 10const throttled = throttle(async index => { 11 const secDiff = ((Date.now() - now) / 1000).toFixed(); 12 return `${index}: ${secDiff}s`; 13}); 14 15for (let index = 1; index <= 6; index++) { 16 (async () => { 17 console.log(await throttled(index)); 18 })(); 19} 20//=> 1: 0s 21//=> 2: 0s 22//=> 3: 1s 23//=> 4: 1s 24//=> 5: 2s 25//=> 6: 2s
Returns a throttle function.
Type: object
Both the limit
and interval
options must be specified.
Type: number
The maximum number of calls within an interval
.
Type: number
The timespan for limit
in milliseconds.
Type: boolean
Default: false
Use a strict, more resource intensive, throttling algorithm. The default algorithm uses a windowed approach that will work correctly in most cases, limiting the total number of calls at the specified limit per interval window. The strict algorithm throttles each call individually, ensuring the limit is not exceeded for any interval.
Type: AbortSignal
Abort pending executions. When aborted, all unresolved promises are rejected with signal.reason
.
1import pThrottle from 'p-throttle'; 2 3const controller = new AbortController(); 4 5const throttle = pThrottle({ 6 limit: 2, 7 interval: 1000, 8 signal: controller.signal 9}); 10 11const throttled = throttle(() => { 12 console.log('Executing...'); 13}); 14 15await throttled(); 16await throttled(); 17controller.abort('aborted') 18await throttled(); 19//=> Executing... 20//=> Executing... 21//=> Promise rejected with reason `aborted`
Type: Function
Get notified when function calls are delayed due to exceeding the limit
of allowed calls within the given interval
. The delayed call arguments are passed to the onDelay
callback.
Can be useful for monitoring the throttling efficiency.
In the following example, the third call gets delayed and triggers the onDelay
callback:
1import pThrottle from 'p-throttle'; 2 3const throttle = pThrottle({ 4 limit: 2, 5 interval: 1000, 6 onDelay: (a, b) => { 7 console.log(`Reached interval limit, call is delayed for ${a} ${b}`); 8 }, 9}); 10 11const throttled = throttle((a, b) => { 12 console.log(`Executing with ${a} ${b}...`); 13}); 14 15await throttled(1, 2); 16await throttled(3, 4); 17await throttled(5, 6); 18//=> Executing with 1 2... 19//=> Executing with 3 4... 20//=> Reached interval limit, call is delayed for 5 6 21//=> Executing with 5 6...
Returns a throttled version of function_
.
Type: Function
A promise-returning/async function or a normal function.
Type: boolean
Default: true
Whether future function calls should be throttled and count towards throttling thresholds.
Type: number
The number of queued items waiting to be executed.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 11/30 approved changesets -- score normalized to 3
Reason
3 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More