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

Comparing version 1.1.1 to 1.2.0

13

CHANGELOG.md
# Changelog
## [1.2.0](https://github.com/superchargejs/promise-pool/compare/v1.1.1...v1.2.0) - 2019-10-15
### Added
- static methods for `.withConcurrency` and `.for`
- moves boilerplate from your code to the promise pool package
- `new Pool().for(items)` is now `Pool.for(items)`)
- `new Pool().withConcurrency(2)` is now `Pool.withConcurrency(2)`)
- it’s always the details :)
### Updated
- bump dependencies
## [1.1.1](https://github.com/superchargejs/promise-pool/compare/v1.1.0...v1.1.1) - 2019-09-24

@@ -5,0 +18,0 @@

2

examples/promise-pool.js

@@ -22,3 +22,3 @@ 'use strict'

const pool = new PromisePool()
const pool = PromisePool
.for(timeouts)

@@ -25,0 +25,0 @@ .withConcurrency(2)

{
"name": "@supercharge/promise-pool",
"description": "Map-like, concurrent promise processing for Node.js",
"version": "1.1.1",
"version": "1.2.0",
"author": "Marcus Pöhls <marcus@futurestud.io>",

@@ -10,5 +10,5 @@ "bugs": {

"devDependencies": {
"@hapi/code": "~6.0.0",
"@hapi/lab": "~20.3.2",
"eslint": "~6.4.0",
"@hapi/code": "~7.0.0",
"@hapi/lab": "~21.0.0",
"eslint": "~6.5.1",
"eslint-config-standard": "~14.1.0",

@@ -15,0 +15,0 @@ "eslint-plugin-import": "~2.18.2",

@@ -45,4 +45,6 @@ <div align="center">

## 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:
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:
```js

@@ -57,5 +59,4 @@ const PromisePool = require('@supercharge/promise-pool')

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

@@ -68,3 +69,14 @@ const user = await User.createIfNotExisting(data)

You can surely refine the concurrency to your needs using the `.withConcurrency` method:
```js
await PromisePool
.for(users)
.withConcurrency(2)
.process(async data => {
//
})
```
## Contributing

@@ -71,0 +83,0 @@

@@ -18,4 +18,3 @@ 'use strict'

/**
* Set the number of tasks to concurrently
* when processing the promise pool.
* Set the number of tasks to process concurrently the promise pool.
*

@@ -33,5 +32,15 @@ * @param {Integer} concurrency

/**
* Set the items to be processed in
* the promise pool.
* Set the number of tasks to process concurrently the promise pool.
*
* @param {Integer} concurrency
*
* @returns {PromisePool}
*/
static withConcurrency (concurrency) {
return new this().withConcurrency(concurrency)
}
/**
* Set the items to be processed in the promise pool.
*
* @param {Array} items

@@ -48,2 +57,13 @@ *

/**
* Set the items to be processed in the promise pool.
*
* @param {Array} items
*
* @returns {PromisePool}
*/
static for (items) {
return new this().for(items)
}
/**
* Starts processing the promise pool by iterating

@@ -50,0 +70,0 @@ * over the items and passing each item to the

@@ -17,2 +17,15 @@ 'use strict'

it('supports a static .for method', async () => {
const users = [1, 2, 3]
const userPool = PromisePool.for(users)
expect(userPool._items).to.equal(users)
expect(userPool instanceof PromisePool).to.be.true()
})
it('supports a static .withConcurrency method', async () => {
const pool = PromisePool.withConcurrency(4)
expect(pool._concurrency).to.equal(4)
expect(pool instanceof PromisePool).to.be.true()
})
it('allows method chaining for the promise pool setup', async () => {

@@ -19,0 +32,0 @@ const users = [1, 2, 3]

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