Socket
Socket
Sign inDemoInstall

@supercharge/promise-pool

Package Overview
Dependencies
0
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @supercharge/promise-pool

Supercharge Promise Pool


Version published
Weekly downloads
384K
decreased by-3.1%
Maintainers
3
Install size
16.8 kB
Created
Weekly downloads
 

Changelog

Source

1.0.0 - 2019-07-15

Added

  • 1.0.0 release 🚀 🎉

Readme

Source


Promise Pool

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


Installation · Usage · API



Build Status Latest Version

Follow @marcuspoehls and @superchargejs for updates!


Installation

npm i @supercharge/promise-pool

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 a working example:

const PromisePool = require('@supercharge/promise-pool')

const users = [
  { name: 'Marcus' },
  { name: 'Norman' },
  { name: 'Christian' }
]

const { results, errors } = await new PromisePool()
  .for(users)
  .withConcurrency(2)
  .process(async user => {
    const user = await User.createIfNotExisting(user)

    return user
  })

API

new PromisePool({ concurrency?, items? }) constructor

Creates a new promise pool. The constructor takes an optional options object allowing you to passing in the concurrency and items.

const pool = new PromisePool({ concurrency: 2, items: [1, 2, 3] })
.withConcurrency(amount)

Set the maximum number of functions to process in parallel. Default concurrency: 10. Returns the promise pool instance.

const pool = new PromisePool().withConcurrency(5)
.for(items)

Set the items to be processed in the promise pool. Returns the promise pool instance.

const users = [
  { name: 'Marcus' },
  { name: 'Norman' },
  { name: 'Christian' }
]

const pool = new PromisePool().withConcurrency(5).for(users)
.process(callback)

Starts processing the promise pool by iterating over the items and passing each item to the async mapper function. Returns an object containing the results and errors.

const users = [
  { name: 'Marcus' },
  { name: 'Norman' },
  { name: 'Christian' }
]

const pool = new PromisePool().withConcurrency(5).for(users)

const { results, errors } = await pool.process(async (user) => {
  await User.createIfNotExisting(user)
})

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

Keywords

FAQs

Last updated on 15 Jul 2019

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc