@supercharge/promise-pool
Advanced tools
Comparing version 1.3.0 to 1.4.0
# Changelog | ||
## [1.4.0](https://github.com/supercharge/streams/compare/v1.3.0...v1.4.0) - 2020-09-17 | ||
### Added | ||
- improved error handling when rejecting a promise without an error instance (thank you [wzh](https://github.com/supercharge/promise-pool/pull/19)) | ||
### Updated | ||
- bump dependencies | ||
- change `main` entrypoint in `package.json` to `dist` folder | ||
- move test runner from `@hapi/lab` to `jest` | ||
- move assertions from `@hapi/code` to `jest` | ||
## [1.3.0](https://github.com/superchargejs/promise-pool/compare/v1.2.0...v1.3.0) - 2020-07-16 | ||
@@ -4,0 +17,0 @@ |
@@ -9,6 +9,23 @@ export declare class PromisePoolError<T> extends Error { | ||
* | ||
* @param message The error message | ||
* @param item The item causing the error | ||
* @param error The original error | ||
* @param item The item causing the error | ||
*/ | ||
constructor(message: string, item: T); | ||
constructor(error: any, item: T); | ||
/** | ||
* Returns a new promise pool error instance wrapping the `error` and `item`. | ||
* | ||
* @param {*} error | ||
* @param {*} item | ||
* | ||
* @returns {PromisePoolError} | ||
*/ | ||
static createFrom<T>(error: any, item: T): PromisePoolError<T>; | ||
/** | ||
* Returns the error message from the given `error`. | ||
* | ||
* @param {*} error | ||
* | ||
* @returns {String} | ||
*/ | ||
private messageFrom; | ||
} |
@@ -8,12 +8,43 @@ 'use strict'; | ||
* | ||
* @param message The error message | ||
* @param item The item causing the error | ||
* @param error The original error | ||
* @param item The item causing the error | ||
*/ | ||
constructor(message, item) { | ||
super(message); | ||
constructor(error, item) { | ||
super(); | ||
this.item = item; | ||
this.name = this.constructor.name; | ||
this.message = this.messageFrom(error); | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
/** | ||
* Returns a new promise pool error instance wrapping the `error` and `item`. | ||
* | ||
* @param {*} error | ||
* @param {*} item | ||
* | ||
* @returns {PromisePoolError} | ||
*/ | ||
static createFrom(error, item) { | ||
return new this(error, item); | ||
} | ||
/** | ||
* Returns the error message from the given `error`. | ||
* | ||
* @param {*} error | ||
* | ||
* @returns {String} | ||
*/ | ||
messageFrom(error) { | ||
if (error instanceof Error) { | ||
return error.message; | ||
} | ||
if (typeof error === 'object') { | ||
return error.message; | ||
} | ||
if (typeof error === 'string' || typeof error === 'number') { | ||
return error.toString(); | ||
} | ||
return ''; | ||
} | ||
} | ||
exports.PromisePoolError = PromisePoolError; |
import { PromisePoolError } from './promise-pool-error'; | ||
export interface ReturnValue { | ||
export interface ReturnValue<T, R> { | ||
/** | ||
* The list of processed items. | ||
*/ | ||
results: any[]; | ||
results: R[]; | ||
/** | ||
@@ -12,5 +12,5 @@ * The list of errors that occurred while processing all items in the pool. | ||
*/ | ||
errors: Array<PromisePoolError<any>>; | ||
errors: Array<PromisePoolError<T>>; | ||
} | ||
export declare class PromisePoolExecutor<T> { | ||
export declare class PromisePoolExecutor<T, R> { | ||
/** | ||
@@ -75,3 +75,3 @@ * The list of items to process. | ||
*/ | ||
start(): Promise<ReturnValue>; | ||
start(): Promise<ReturnValue<T, R>>; | ||
/** | ||
@@ -91,3 +91,3 @@ * Ensure valid inputs and throw otherwise. | ||
*/ | ||
process(): Promise<ReturnValue>; | ||
process(): Promise<ReturnValue<T, R>>; | ||
/** | ||
@@ -122,3 +122,3 @@ * Create a processing function for the given `item`. | ||
*/ | ||
drained(): Promise<ReturnValue>; | ||
drained(): Promise<ReturnValue<T, R>>; | ||
/** | ||
@@ -125,0 +125,0 @@ * Determines whether the number of active tasks is greater or equal to the concurrency limit. |
@@ -111,3 +111,3 @@ 'use strict'; | ||
.catch(error => { | ||
this.errors.push(new promise_pool_error_1.PromisePoolError(error.message, item)); | ||
this.errors.push(promise_pool_error_1.PromisePoolError.createFrom(error, item)); | ||
}); | ||
@@ -114,0 +114,0 @@ this.tasks.push(task); |
@@ -58,3 +58,3 @@ import { ReturnValue } from './promise-pool-executor'; | ||
*/ | ||
process(callback: (item: T) => any): Promise<ReturnValue>; | ||
process<R>(callback: (item: T) => R): Promise<ReturnValue<T, R>>; | ||
} |
{ | ||
"name": "@supercharge/promise-pool", | ||
"description": "Map-like, concurrent promise processing for Node.js", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"author": "Marcus Pöhls <marcus@futurestud.io>", | ||
@@ -10,12 +10,11 @@ "bugs": { | ||
"dependencies": { | ||
"@supercharge/goodies": "~1.4.0" | ||
"@supercharge/goodies": "~1.5.1" | ||
}, | ||
"devDependencies": { | ||
"@hapi/code": "~7.0.0", | ||
"@hapi/lab": "~21.0.0", | ||
"@supercharge/tsconfig": "~1.0.0", | ||
"@typescript-eslint/eslint-plugin": "~3.6.1", | ||
"eslint": "~6.8.0", | ||
"@types/jest": "~26.0.14", | ||
"@typescript-eslint/eslint-plugin": "~4.1.1", | ||
"eslint": "~7.9.0", | ||
"eslint-config-standard": "~14.1.1", | ||
"eslint-config-standard-with-typescript": "~18.0.2", | ||
"eslint-config-standard-with-typescript": "~19.0.1", | ||
"eslint-plugin-import": "~2.22.0", | ||
@@ -25,3 +24,5 @@ "eslint-plugin-node": "~11.1.0", | ||
"eslint-plugin-standard": "~4.0.1", | ||
"typescript": "~3.9.6" | ||
"jest": "~26.4.2", | ||
"jest-extended": "~0.11.5", | ||
"typescript": "~4.0.2" | ||
}, | ||
@@ -44,6 +45,5 @@ "engines": { | ||
"files": [ | ||
"dist", | ||
"index.js" | ||
"dist" | ||
], | ||
"main": "index.js", | ||
"main": "dist", | ||
"publishConfig": { | ||
@@ -60,9 +60,7 @@ "access": "public" | ||
"lint": "eslint src --ext .js,.ts", | ||
"lint:fix": "eslint src --ext .js,.ts --fix", | ||
"lint:fix": "npm run lint -- --fix", | ||
"test": "npm run build && npm run lint && npm run test:run", | ||
"test:list": "lab --assert @hapi/code --dry --verbose", | ||
"test:run": "lab --assert @hapi/code --leaks --coverage --reporter console --output stdout --reporter html --output ./coverage/coverage.html", | ||
"test:single": "npm run build && lab --assert @hapi/code --leaks --id" | ||
"test:run": "jest" | ||
}, | ||
"types": "dist" | ||
} |
@@ -24,3 +24,2 @@ <div align="center"> | ||
<a href="https://www.npmjs.com/package/@supercharge/promise-pool"><img src="https://img.shields.io/npm/dm/@supercharge/promise-pool.svg" alt="Monthly downloads"></a> | ||
</p> | ||
@@ -48,3 +47,3 @@ <p> | ||
Here’s an example using the default concurrency of 10: | ||
Here’s an example using a concurrency of 2: | ||
@@ -61,2 +60,3 @@ ```js | ||
const { results, errors } = await PromisePool | ||
.withConcurrency(2) | ||
.for(users) | ||
@@ -70,3 +70,3 @@ .process(async data => { | ||
You can surely refine the concurrency to your needs using the `.withConcurrency` method: | ||
The promise pool uses a default concurrency of 10: | ||
@@ -76,5 +76,4 @@ ```js | ||
.for(users) | ||
.withConcurrency(2) | ||
.process(async data => { | ||
// | ||
// processes 10 items in parallel by default | ||
}) | ||
@@ -81,0 +80,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21188
525
0
13
12
95
+ Added@supercharge/goodies@1.5.1(transitive)
- Removed@supercharge/goodies@1.4.0(transitive)
Updated@supercharge/goodies@~1.5.1