Promise Pool
Map-like, concurrent promise processing for Node.js.
Installation · Docs · Usage
Follow @marcuspoehls and @superchargejs for updates!
Installation
npm i @supercharge/promise-pool
Docs
Find all the details and available methods in the extensive Supercharge docs.
Usage
Using the promise pool is pretty straightforward. The pacakge exposes a class and you can create a promise pool instance using the fluent interface.
Here’s an example using the default concurrency of 10:
const PromisePool = require('@supercharge/promise-pool')
const users = [
{ name: 'Marcus' },
{ name: 'Norman' },
{ name: 'Christian' }
]
const { results, errors } = await PromisePool
.for(users)
.process(async data => {
const user = await User.createIfNotExisting(data)
return user
})
You can surely refine the concurrency to your needs using the .withConcurrency
method:
await PromisePool
.for(users)
.withConcurrency(2)
.process(async data => {
//
})
Contributing
- Create a fork
- Create your feature branch:
git checkout -b my-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
🚀
License
MIT © Supercharge
superchargejs.com · GitHub @superchargejs · Twitter @superchargejs