Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added onProgress function and made some code refactors #34

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
{
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": [
"standard-with-typescript"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"@typescript-eslint/return-await": 0,
"@typescript-eslint/require-await": 0,
"@typescript-eslint/strict-boolean-expressions": 0
}
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": ["standard-with-typescript"],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"semi": ["error", "always"],
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/indent": ["off"],
"@typescript-eslint/quotes": ["error", "always"],
"@typescript-eslint/space-before-function-paren": ["off"],
"@typescript-eslint/member-delimiter-style": ["off"],
"comma-dangle": ["off"],
"quotes": ["single", "always"],
"indent": 0,
"no-tabs": 0,
"@typescript-eslint/return-await": 0,
"@typescript-eslint/require-await": 0,
"@typescript-eslint/strict-boolean-expressions": 0
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ coverage
.vscode

.vagrant
yarn.lock
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
'use strict';

import { PromisePool } from './promise-pool'
import { PromisePool } from './promise-pool';

export = PromisePool
export = PromisePool;
112 changes: 56 additions & 56 deletions src/promise-pool-error.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
'use strict'
'use strict';

export class PromisePoolError<T> extends Error {
/**
* Returns the item that caused this error.
*/
public item: T

/**
* Create a new instance for the given `message` and `item`.
*
* @param error The original error
* @param item The item causing the error
*/
constructor (error: any, item: T) {
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<T>(error: any, item: T): PromisePoolError<T> {
return new this(error, item)
}

/**
* Returns the error message from the given `error`.
*
* @param {*} error
*
* @returns {String}
*/
private messageFrom (error: any): string {
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 ''
}
/**
* Returns the item that caused this error.
*/
public item: T;

/**
* Create a new instance for the given `message` and `item`.
*
* @param error The original error
* @param item The item causing the error
*/
constructor(error: any, item: T) {
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<T>(error: any, item: T): PromisePoolError<T> {
return new this(error, item);
}

/**
* Returns the error message from the given `error`.
*
* @param {*} error
*
* @returns {String}
*/
private messageFrom(error: any): string {
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 '';
}
}
Loading