Socket
Socket
Sign inDemoInstall

@supercharge/promise-pool

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@supercharge/promise-pool - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

dist/return-value.d.ts

8

CHANGELOG.md
# Changelog
## [1.5.0](https://github.com/supercharge/streams/compare/v1.4.0...v1.5.0) - 2020-09-20
### Updated
- bump dependencies
- return types for `results` and `errors` now resolve properly for sync and async action handlers
## [1.4.0](https://github.com/supercharge/streams/compare/v1.3.0...v1.4.0) - 2020-09-17
### Added
- improved types supporting typed return values
- improved error handling when rejecting a promise without an error instance (thank you [wzh](https://github.com/supercharge/promise-pool/pull/19))

@@ -8,0 +16,0 @@

68

dist/promise-pool-executor.d.ts

@@ -1,14 +0,2 @@

import { PromisePoolError } from './promise-pool-error';
export interface ReturnValue<T, R> {
/**
* The list of processed items.
*/
results: R[];
/**
* The list of errors that occurred while processing all items in the pool.
* Each error contains the error-causing item at `error.item` as a
* reference for re-processing.
*/
errors: Array<PromisePoolError<T>>;
}
import { ReturnValue } from './return-value';
export declare class PromisePoolExecutor<T, R> {

@@ -40,5 +28,3 @@ /**

/**
* Instantiates a new promise pool with a default `concurrency: 10` and `items: []`.
*
* @param {Object} options
* Creates a new promise pool executer instance with a default concurrency of 10.
*/

@@ -61,12 +47,24 @@ constructor();

*/
for(items: any[]): this;
for(items: T[]): this;
/**
* Set the handler that is applied to each item.
*
* @param {Function} handler
* @param {Function} action
*
* @returns {PromisePoolExecutor}
*/
withHandler(handler: (item: T) => any): this;
withHandler(action: (item: T) => R): this;
/**
* Determines whether the number of active tasks is greater or equal to the concurrency limit.
*
* @returns {Boolean}
*/
hasReachedConcurrencyLimit(): boolean;
/**
* Returns the number of active tasks.
*
* @returns {Number}
*/
activeCount(): number;
/**
* Start processing the promise pool.

@@ -93,2 +91,13 @@ *

/**
* Creates a deferred promise and pushes the related callback to the pending
* queue. Returns the promise which is used to wait for the callback.
*
* @returns {Promise}
*/
processingSlot(): Promise<void>;
/**
* Wait for one of the active tasks to finish processing.
*/
waitForTaskToFinish(): Promise<void>;
/**
* Create a processing function for the given `item`.

@@ -108,11 +117,2 @@ *

/**
* Creates a deferred promise and pushes the related callback to the pending
* queue. Returns the promise which is used to wait for the callback.
*
* @returns {Promise}
*/
processingSlot(): Promise<void>;
waitForTaskToFinish(): Promise<void>;
drainActiveTasks(): Promise<void>;
/**
* Wait for all active tasks to finish. Once all the tasks finished

@@ -125,13 +125,5 @@ * processing, returns an object containing the results and errors.

/**
* Determines whether the number of active tasks is greater or equal to the concurrency limit.
*
* @returns {Boolean}
* Wait for all of the active tasks to finish processing.
*/
hasReachedConcurrencyLimit(): boolean;
/**
* Returns the number of active tasks.
*
* @returns {Number}
*/
activeCount(): number;
drainActiveTasks(): Promise<void>;
}

@@ -8,5 +8,3 @@ 'use strict';

/**
* Instantiates a new promise pool with a default `concurrency: 10` and `items: []`.
*
* @param {Object} options
* Creates a new promise pool executer instance with a default concurrency of 10.
*/

@@ -48,12 +46,28 @@ constructor() {

*
* @param {Function} handler
* @param {Function} action
*
* @returns {PromisePoolExecutor}
*/
withHandler(handler) {
withHandler(action) {
return goodies_1.tap(this, () => {
this.handler = handler;
this.handler = action;
});
}
/**
* Determines whether the number of active tasks is greater or equal to the concurrency limit.
*
* @returns {Boolean}
*/
hasReachedConcurrencyLimit() {
return this.activeCount() >= this.concurrency;
}
/**
* Returns the number of active tasks.
*
* @returns {Number}
*/
activeCount() {
return this.tasks.length;
}
/**
* Start processing the promise pool.

@@ -102,2 +116,17 @@ *

/**
* Creates a deferred promise and pushes the related callback to the pending
* queue. Returns the promise which is used to wait for the callback.
*
* @returns {Promise}
*/
async processingSlot() {
return this.waitForTaskToFinish();
}
/**
* Wait for one of the active tasks to finish processing.
*/
async waitForTaskToFinish() {
await Promise.race(this.tasks);
}
/**
* Create a processing function for the given `item`.

@@ -129,17 +158,2 @@ *

/**
* Creates a deferred promise and pushes the related callback to the pending
* queue. Returns the promise which is used to wait for the callback.
*
* @returns {Promise}
*/
async processingSlot() {
return this.waitForTaskToFinish();
}
async waitForTaskToFinish() {
await Promise.race(this.tasks);
}
async drainActiveTasks() {
await Promise.all(this.tasks);
}
/**
* Wait for all active tasks to finish. Once all the tasks finished

@@ -153,3 +167,3 @@ * processing, returns an object containing the results and errors.

return {
results: await Promise.all(this.results),
results: this.results,
errors: this.errors

@@ -159,18 +173,8 @@ };

/**
* Determines whether the number of active tasks is greater or equal to the concurrency limit.
*
* @returns {Boolean}
* Wait for all of the active tasks to finish processing.
*/
hasReachedConcurrencyLimit() {
return this.activeCount() >= this.concurrency;
async drainActiveTasks() {
await Promise.all(this.tasks);
}
/**
* Returns the number of active tasks.
*
* @returns {Number}
*/
activeCount() {
return this.tasks.length;
}
}
exports.PromisePoolExecutor = PromisePoolExecutor;

@@ -1,2 +0,2 @@

import { ReturnValue } from './promise-pool-executor';
import { ReturnValue } from './return-value';
export declare class PromisePool<T> {

@@ -58,3 +58,3 @@ /**

*/
process<R>(callback: (item: T) => R): Promise<ReturnValue<T, R>>;
process<R>(callback: (item: T) => Promise<R>): Promise<ReturnValue<T, R>>;
}

@@ -64,10 +64,2 @@ 'use strict';

}
/**
* Starts processing the promise pool by iterating over the items
* and running each item through the async `callback` function.
*
* @param {Function} The async processing function receiving each item from the `items` array.
*
* @returns Promise<{ results, errors }>
*/
async process(callback) {

@@ -74,0 +66,0 @@ return new promise_pool_executor_1.PromisePoolExecutor()

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

@@ -25,3 +25,3 @@ "bugs": {

"jest-extended": "~0.11.5",
"typescript": "~4.0.2"
"typescript": "~4.0.3"
},

@@ -28,0 +28,0 @@ "engines": {

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc