Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@supercharge/promise-pool
Advanced tools
Changelog
1.7.0 - 2021-04-11
@supercharge/goodies
package@supercharge/goodies
Readme
Map-like, concurrent promise processing for Node.js.
Installation · Docs · Usage
Follow @marcuspoehls and @superchargejs for updates!
npm i @supercharge/promise-pool
Find all the details and available methods in the extensive Supercharge docs.
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:
const PromisePool = require('@supercharge/promise-pool')
const users = [
{ name: 'Marcus' },
{ name: 'Norman' },
{ name: 'Christian' }
]
const { results, errors } = await PromisePool
.withConcurrency(2)
.for(users)
.process(async data => {
const user = await User.createIfNotExisting(data)
return user
})
The promise pool uses a default concurrency of 10:
await PromisePool
.for(users)
.process(async data => {
// processes 10 items in parallel by default
})
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.
try {
const errors = []
const { results } = await PromisePool
.for(users)
.withConcurrency(4)
.handleError(async (error, user) => {
if (error instanceof ValidationError) {
errors.push(error) // you must collect errors yourself
return
}
if (error instanceof ThrottleError) { // Execute error handling on specific errors
await retryUser(user)
return
}
throw error // Uncaught errors will immediately stop PromisePool
})
.process(async data => {
// the harder you work for something,
// the greater you’ll feel when you achieve it
})
await handleCollected(errors) // this may throw
return { results }
} catch (error) {
await handleThrown(error)
}
git checkout -b my-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT © Supercharge
superchargejs.com · GitHub @superchargejs · Twitter @superchargejs
FAQs
Map-like, concurrent promise processing for Node.js
We found that @supercharge/promise-pool demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).