Gathering detailed insights and metrics for @kayanski/promise-pool
Gathering detailed insights and metrics for @kayanski/promise-pool
npm install @kayanski/promise-pool
Typescript
Module System
Min. Node Version
Node Version
NPM Version
74
Supply Chain
99.4
Quality
75.3
Maintenance
100
Vulnerability
100
License
JavaScript (52.93%)
TypeScript (47.07%)
Total Downloads
724
Last Day
2
Last Week
6
Last Month
31
Last Year
229
803 Stars
332 Commits
42 Forks
11 Watching
1 Branches
15 Contributors
Minified
Minified + Gzipped
Latest Version
3.0.3
Package Id
@kayanski/promise-pool@3.0.3
Unpacked Size
42.32 kB
Size
8.89 kB
File Count
19
NPM Version
8.5.0
Node Version
16.14.2
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
-40%
6
Compared to previous week
Last month
342.9%
31
Compared to previous month
Last year
11.7%
229
Compared to previous year
Map-like, concurrent promise processing for Node.js.
Installation · Docs · Usage
Follow @marcuspoehls and @superchargejs for updates!
npm i @supercharge/promise-pool
Using the promise pool is pretty straightforward. The package exposes a class and you can create a promise pool instance using the fluent interface.
Here’s an example using a concurrency of 2:
1const { PromisePool } = require('@supercharge/promise-pool') 2 3const users = [ 4 { name: 'Marcus' }, 5 { name: 'Norman' }, 6 { name: 'Christian' } 7] 8 9const { results, errors } = await PromisePool 10 .withConcurrency(2) 11 .for(users) 12 .process(async (userData, index, pool) => { 13 const user = await User.createIfNotExisting(userData) 14 15 return user 16 })
The promise pool uses a default concurrency of 10:
1await PromisePool 2 .for(users) 3 .process(async data => { 4 // processes 10 items in parallel by default 5 })
You can stop the processing of a promise pool using the pool
instance provided to the .process()
and .handleError()
methods. Here’s an example how you can stop an active promise pool from within the .process()
method:
1await PromisePool 2 .for(users) 3 .process(async (user, index, pool) => { 4 if (condition) { 5 return pool.stop() 6 } 7 8 // processes the `user` data 9 })
You may also stop the pool from within the .handleError()
method in case you need to:
1const { PromisePool } = require('@supercharge/promise-pool') 2 3await PromisePool 4 .for(users) 5 .handleError(async (error, user, pool) => { 6 if (error instanceof SomethingBadHappenedError) { 7 return pool.stop() 8 } 9 10 // handle the given `error` 11 }) 12 .process(async (user, index, pool) => { 13 // processes the `user` data 14 })
The promise pool allows for custom error handling. You can take over the error handling by implementing an error handler using the .handleError(handler)
.
If you provide an error handler, the promise pool doesn’t collect any errors. You must then collect errors yourself.
Providing a custom error handler allows you to exit the promise pool early by throwing inside the error handler function. Throwing errors is in line with Node.js error handling using async/await.
1const { PromisePool } = require('@supercharge/promise-pool') 2 3try { 4 const errors = [] 5 6 const { results } = await PromisePool 7 .for(users) 8 .withConcurrency(4) 9 .handleError(async (error, user) => { 10 if (error instanceof ValidationError) { 11 errors.push(error) // you must collect errors yourself 12 return 13 } 14 15 if (error instanceof ThrottleError) { // Execute error handling on specific errors 16 await retryUser(user) 17 return 18 } 19 20 throw error // Uncaught errors will immediately stop PromisePool 21 }) 22 .process(async data => { 23 // the harder you work for something, 24 // the greater you’ll feel when you achieve it 25 }) 26 27 await handleCollected(errors) // this may throw 28 29 return { results } 30} catch (error) { 31 await handleThrown(error) 32}
You can use the onTaskStarted
and onTaskFinished
methods to hook into the processing of tasks. The provided callback for each method will be called when a task started/finished processing:
1const { PromisePool } = require('@supercharge/promise-pool') 2 3await PromisePool 4 .for(users) 5 .onTaskStarted((item, pool) => { 6 console.log(`Progress: ${pool.processedPercentage()}%`) 7 console.log(`Active tasks: ${pool.processedItems().length}`) 8 console.log(`Active tasks: ${pool.activeTasksCount()}`) 9 console.log(`Finished tasks: ${pool.processedItems().length}`) 10 console.log(`Finished tasks: ${pool.processedCount()}`) 11 }) 12 .onTaskFinished((item, pool) => { 13 // update a progress bar or something else :) 14 }) 15 .process(async (user, index, pool) => { 16 // processes the `user` data 17 })
You can also chain multiple onTaskStarted
and onTaskFinished
handling (in case you want to separate some functionality):
1const { PromisePool } = require('@supercharge/promise-pool') 2 3await PromisePool 4 .for(users) 5 .onTaskStarted(() => {}) 6 .onTaskStarted(() => {}) 7 .onTaskFinished(() => {}) 8 .onTaskFinished(() => {}) 9 .process(async (user, index, pool) => { 10 // processes the `user` data 11 })
git checkout -b my-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT © Supercharge
superchargejs.com  · GitHub @supercharge  · Twitter @superchargejs
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 2/28 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
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
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
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