celiktemha / promise-pool

Map-like, concurrent promise processing

Home Page:https://superchargejs.com/docs/promise-pool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool



Promise Pool

Map-like, concurrent promise processing for Node.js.


Installation · Docs · Usage



Latest Version Monthly downloads

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

  1. Create a fork
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 🚀

License

MIT © Supercharge


superchargejs.com  ·  GitHub @superchargejs  ·  Twitter @superchargejs

About

Map-like, concurrent promise processing

https://superchargejs.com/docs/promise-pool

License:MIT License


Languages

Language:JavaScript 100.0%