{
skipWords: [
'poolifier',
- 'pioardi',
'christopher',
'ecma',
+ 'enum',
'jsdoc',
+ 'pioardi',
'readonly',
'serializable',
'unregister',
files: ['src/**/*.ts'],
extends: 'plugin:jsdoc/recommended',
rules: {
+ 'jsdoc/match-description': [
+ 'warn',
+ {
+ mainDescription:
+ '/^[A-Z`].+?(\\.|:)(\\n\\n.*((\\n{1,2}- .+)|(_.+_)|`.+`|\\n\\n---))?$/us',
+ matchDescription: '^[A-Z`].+(\\.|`.+`)$',
+ contexts: ['any'],
+ tags: {
+ param: true,
+ returns: true
+ }
+ }
+ ],
'jsdoc/no-types': 'error',
+ 'jsdoc/require-jsdoc': [
+ 'warn',
+ {
+ contexts: [
+ 'ClassDeclaration',
+ 'ClassProperty:not([accessibility=/(private|protected)/])',
+ 'ExportNamedDeclaration:has(VariableDeclaration)',
+ 'FunctionExpression',
+ 'MethodDefinition:not([accessibility=/(private|protected)/]) > FunctionExpression',
+ 'TSEnumDeclaration',
+ 'TSInterfaceDeclaration',
+ 'TSMethodSignature',
+ // 'TSPropertySignature',
+ 'TSTypeAliasDeclaration'
+ ]
+ }
+ ],
'jsdoc/require-param-type': 'off',
'jsdoc/require-returns-type': 'off'
}
'node/no-missing-require': 'off'
}
}
- ]
+ ],
+ settings: {
+ jsdoc: {
+ mode: 'typescript'
+ }
+ }
}
`opts` (optional) An object with these properties:
- `maxInactiveTime` - Max time to wait tasks to work on (in ms), after this period the new worker threads will die.
-The last active time of your worker unit will be updated when a task is submitted to a worker or when a worker terminate a task.
-If `killBehavior` is set to `KillBehaviors.HARD` this value represents also the timeout for the tasks that you submit to the pool, when this timeout expires your tasks is interrupted and the worker is killed if is not part of the minimum size of the pool.
-If `killBehavior` is set to `KillBehaviors.SOFT` your tasks have no timeout and your workers will not be terminated until your task is completed.
-Default: 60.000 ms
+ The last active time of your worker unit will be updated when a task is submitted to a worker or when a worker terminate a task.
+ If `killBehavior` is set to `KillBehaviors.HARD` this value represents also the timeout for the tasks that you submit to the pool, when this timeout expires your tasks is interrupted and the worker is killed if is not part of the minimum size of the pool.
+ If `killBehavior` is set to `KillBehaviors.SOFT` your tasks have no timeout and your workers will not be terminated until your task is completed.
+ Default: 60.000 ms
- `async` - true/false, true if your function contains async pieces else false
- `killBehavior` - Dictates if your async unit (worker/process) will be deleted in case that a task is active on it.
-**SOFT**: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker **wont** be deleted.
-**HARD**: If `lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker will be deleted.
-This option only apply to the newly created workers.
-Default: `SOFT`
+ **SOFT**: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker **wont** be deleted.
+ **HARD**: If `lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker will be deleted.
+ This option only apply to the newly created workers.
+ Default: `SOFT`
## Choose your pool
}
},
"eslint-plugin-jsdoc": {
- "version": "32.0.1",
- "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-32.0.1.tgz",
- "integrity": "sha512-7T6cKNGJsJ1SxhG4vbEBi2fRmUL3DHzRNsiQZri4vkgIQjCoBb40ZNxSNwBqiVz16C7tW3qLncPoNXsiIFdzcg==",
+ "version": "32.0.2",
+ "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-32.0.2.tgz",
+ "integrity": "sha512-zMAJAsq02uWVGrmr6TVlJ2nue0wM/94loWb+0Z/aJcX+oELIet+Z1vtSU9xoSkPaOJE1tpI6CkHgUZfVLKTaJg==",
"dev": true,
"requires": {
"comment-parser": "1.1.2",
"eslint": "^7.20.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
- "eslint-plugin-jsdoc": "^32.0.1",
+ "eslint-plugin-jsdoc": "^32.0.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettierx": "^0.17.1",
"eslint-plugin-promise": "^4.3.1",
* Basic interface that describes the minimum required implementation of listener events for a pool-worker.
*/
export interface IWorker {
+ /**
+ * Register a listener to the error event.
+ *
+ * @param event `'error'`.
+ * @param handler The error handler.
+ */
on(event: 'error', handler: ErrorHandler<this>): void
+ /**
+ * Register a listener to the online event.
+ *
+ * @param event `'online'`.
+ * @param handler The online handler.
+ */
on(event: 'online', handler: OnlineHandler<this>): void
+ /**
+ * Register a listener to the exit event.
+ *
+ * @param event `'exit'`.
+ * @param handler The exit handler.
+ */
on(event: 'exit', handler: ExitHandler<this>): void
+ /**
+ * Register a listener to the exit event that will only performed once.
+ *
+ * @param event `'exit'`.
+ * @param handler The exit handler.
+ */
once(event: 'exit', handler: ExitHandler<this>): void
}
public nextWorkerIndex: number = 0
/**
+ * The tasks map.
+ *
* - `key`: The `Worker`
* - `value`: Number of tasks currently in progress on the worker.
*/
return this.nextWorkerIndex
}
+ /**
+ * Perform the task specified in the constructor with the data parameter.
+ *
+ * @param data The input for the specified task.
+ * @returns Promise that will be resolved when the task is successfully completed.
+ */
public execute (data: Data): Promise<Response> {
// Configure worker to handle message with the specified task
const worker = this.chooseWorker()
return res
}
+ /**
+ * Shut down every current worker in this pool.
+ */
public async destroy (): Promise<void> {
await Promise.all(this.workers.map(worker => this.destroyWorker(worker)))
}
import type { KillBehavior } from './worker/worker-options'
/**
- * Make all properties in T non-readonly
+ * Make all properties in T non-readonly.
*/
export type Draft<T> = { -readonly [P in keyof T]?: T[P] }