From 38e795c12f0e9daeff7b025147f36f85f486366e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 3 Jan 2023 18:47:20 +0100 Subject: [PATCH] Initial comment conversion to TSDoc MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .eslintrc.js | 48 ++-------- .vscode/settings.json | 1 + package-lock.json | 94 +++++++++++++++++++ package.json | 1 + src/pools/abstract-pool.ts | 84 ++++++++--------- src/pools/cluster/dynamic.ts | 16 ++-- src/pools/cluster/fixed.ts | 28 +++--- src/pools/pool-internal.ts | 12 +-- src/pools/pool-worker.ts | 8 +- src/pools/pool.ts | 10 +- .../abstract-worker-choice-strategy.ts | 16 ++-- .../dynamic-pool-worker-choice-strategy.ts | 16 ++-- .../fair-share-worker-choice-strategy.ts | 14 +-- ...ss-recently-used-worker-choice-strategy.ts | 10 +- .../round-robin-worker-choice-strategy.ts | 10 +- .../selection-strategies-types.ts | 2 +- .../selection-strategies-utils.ts | 4 +- ...hted-round-robin-worker-choice-strategy.ts | 14 +-- .../worker-choice-strategy-context.ts | 16 ++-- src/pools/thread/dynamic.ts | 16 ++-- src/pools/thread/fixed.ts | 26 ++--- src/utility-types.ts | 4 +- src/worker/abstract-worker.ts | 30 +++--- src/worker/cluster-worker.ts | 12 +-- src/worker/thread-worker.ts | 10 +- src/worker/worker-options.ts | 12 +-- 26 files changed, 288 insertions(+), 226 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index fd8a538d..5c52e0f0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,11 +12,10 @@ module.exports = defineConfig({ ecmaVersion: 2021, sourceType: 'module' }, - plugins: ['promise', 'jsdoc', 'spellcheck'], + plugins: ['promise', 'spellcheck'], extends: [ 'eslint:recommended', 'plugin:import/recommended', - 'plugin:jsdoc/recommended', 'plugin:promise/recommended' ], rules: { @@ -61,6 +60,7 @@ module.exports = defineConfig({ 'threadjs', 'threadwork', 'tsconfig', + 'tsdoc', 'typedoc', 'unlink', 'unregister', @@ -74,11 +74,11 @@ module.exports = defineConfig({ overrides: [ { files: ['**/*.ts'], + plugins: ['@typescript-eslint', 'eslint-plugin-tsdoc'], parser: '@typescript-eslint/parser', parserOptions: { project: './tsconfig.json' }, - plugins: ['@typescript-eslint'], extends: [ 'plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended', @@ -97,43 +97,13 @@ module.exports = defineConfig({ 'no-useless-constructor': 'off', - 'jsdoc/match-description': [ - 'warn', - { - 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' + 'tsdoc/syntax': 'warn' } }, { files: ['examples/typescript/**/*.ts'], rules: { 'import/no-unresolved': 'off', - 'jsdoc/require-jsdoc': 'off', '@typescript-eslint/no-unsafe-argument': 'off', '@typescript-eslint/no-unsafe-call': 'off', '@typescript-eslint/no-unsafe-assignment': 'off' @@ -141,7 +111,8 @@ module.exports = defineConfig({ }, { files: ['**/*.js'], - extends: ['plugin:n/recommended', 'standard'] + plugins: ['jsdoc'], + extends: ['plugin:n/recommended', 'standard', 'plugin:jsdoc/recommended'] }, { files: ['tests/**/*.js'], @@ -174,10 +145,5 @@ module.exports = defineConfig({ 'jsdoc/require-jsdoc': 'off' } } - ], - settings: { - jsdoc: { - mode: 'typescript' - } - } + ] }) diff --git a/.vscode/settings.json b/.vscode/settings.json index f44a08d9..865aa283 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -30,6 +30,7 @@ "suchmokuo", "threadjs", "threadwork", + "tsdoc", "workerpool" ], "sonarlint.connectedMode.project": { diff --git a/package-lock.json b/package-lock.json index a4f204ee..f4dd957d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "eslint-plugin-n": "^15.6.0", "eslint-plugin-promise": "^6.1.1", "eslint-plugin-spellcheck": "^0.0.20", + "eslint-plugin-tsdoc": "^0.2.17", "expect": "^29.3.1", "husky": "^8.0.2", "lint-staged": "^13.1.0", @@ -402,6 +403,37 @@ "integrity": "sha512-EWUguj2kd7ldmrF9F+vI5hUOralPd+sdsUnYbRy33vZTuZkduC1shE9TtEMEjAQwyfyMb4ole5KtjF8MsnQOlA==", "dev": true }, + "node_modules/@microsoft/tsdoc": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.14.2.tgz", + "integrity": "sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==", + "dev": true + }, + "node_modules/@microsoft/tsdoc-config": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc-config/-/tsdoc-config-0.16.2.tgz", + "integrity": "sha512-OGiIzzoBLgWWR0UdRJX98oYO+XKGf7tiK4Zk6tQ/E4IJqGCe7dvkTvgDZV5cFJUzLGDOjeAXrnZoA6QkVySuxw==", + "dev": true, + "dependencies": { + "@microsoft/tsdoc": "0.14.2", + "ajv": "~6.12.6", + "jju": "~1.4.0", + "resolve": "~1.19.0" + } + }, + "node_modules/@microsoft/tsdoc-config/node_modules/resolve": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz", + "integrity": "sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==", + "dev": true, + "dependencies": { + "is-core-module": "^2.1.0", + "path-parse": "^1.0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -3328,6 +3360,16 @@ "eslint": ">=0.8.0" } }, + "node_modules/eslint-plugin-tsdoc": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/eslint-plugin-tsdoc/-/eslint-plugin-tsdoc-0.2.17.tgz", + "integrity": "sha512-xRmVi7Zx44lOBuYqG8vzTXuL6IdGOeF9nHX17bjJ8+VE6fsxpdGem0/SBTmAwgYMKYB1WBkqRJVQ+n8GK041pA==", + "dev": true, + "dependencies": { + "@microsoft/tsdoc": "0.14.2", + "@microsoft/tsdoc-config": "0.16.2" + } + }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -5372,6 +5414,12 @@ "node": ">= 10.13.0" } }, + "node_modules/jju": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz", + "integrity": "sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==", + "dev": true + }, "node_modules/js-sdsl": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.4.tgz", @@ -9879,6 +9927,36 @@ "integrity": "sha512-EWUguj2kd7ldmrF9F+vI5hUOralPd+sdsUnYbRy33vZTuZkduC1shE9TtEMEjAQwyfyMb4ole5KtjF8MsnQOlA==", "dev": true }, + "@microsoft/tsdoc": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.14.2.tgz", + "integrity": "sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==", + "dev": true + }, + "@microsoft/tsdoc-config": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc-config/-/tsdoc-config-0.16.2.tgz", + "integrity": "sha512-OGiIzzoBLgWWR0UdRJX98oYO+XKGf7tiK4Zk6tQ/E4IJqGCe7dvkTvgDZV5cFJUzLGDOjeAXrnZoA6QkVySuxw==", + "dev": true, + "requires": { + "@microsoft/tsdoc": "0.14.2", + "ajv": "~6.12.6", + "jju": "~1.4.0", + "resolve": "~1.19.0" + }, + "dependencies": { + "resolve": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz", + "integrity": "sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==", + "dev": true, + "requires": { + "is-core-module": "^2.1.0", + "path-parse": "^1.0.6" + } + } + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -12037,6 +12115,16 @@ "lodash": "^4.17.15" } }, + "eslint-plugin-tsdoc": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/eslint-plugin-tsdoc/-/eslint-plugin-tsdoc-0.2.17.tgz", + "integrity": "sha512-xRmVi7Zx44lOBuYqG8vzTXuL6IdGOeF9nHX17bjJ8+VE6fsxpdGem0/SBTmAwgYMKYB1WBkqRJVQ+n8GK041pA==", + "dev": true, + "requires": { + "@microsoft/tsdoc": "0.14.2", + "@microsoft/tsdoc-config": "0.16.2" + } + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -13417,6 +13505,12 @@ "supports-color": "^7.0.0" } }, + "jju": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz", + "integrity": "sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==", + "dev": true + }, "js-sdsl": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.4.tgz", diff --git a/package.json b/package.json index 56527fd6..d0475326 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,7 @@ "eslint-plugin-n": "^15.6.0", "eslint-plugin-promise": "^6.1.1", "eslint-plugin-spellcheck": "^0.0.20", + "eslint-plugin-tsdoc": "^0.2.17", "expect": "^29.3.1", "husky": "^8.0.2", "lint-staged": "^13.1.0", diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 6b12c2f9..c2b54b58 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -18,25 +18,25 @@ import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choic /** * Base class that implements some shared logic for all poolifier pools. * - * @template Worker Type of worker which manages this pool. - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Worker - Type of worker which manages this pool. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. */ export abstract class AbstractPool< Worker extends IPoolWorker, Data = unknown, Response = unknown > implements IPoolInternal { - /** @inheritDoc */ + /** {@inheritDoc} */ public readonly workers: Worker[] = [] - /** @inheritDoc */ + /** {@inheritDoc} */ public readonly workersTasksUsage: Map = new Map< Worker, TasksUsage >() - /** @inheritDoc */ + /** {@inheritDoc} */ public readonly emitter?: PoolEmitter /** @@ -71,9 +71,9 @@ export abstract class AbstractPool< /** * Constructs a new poolifier pool. * - * @param numberOfWorkers Number of workers that this pool should manage. - * @param filePath Path to the worker-file. - * @param opts Options for the pool. + * @param numberOfWorkers - Number of workers that this pool should manage. + * @param filePath - Path to the worker-file. + * @param opts - Options for the pool. */ public constructor ( public readonly numberOfWorkers: number, @@ -144,30 +144,30 @@ export abstract class AbstractPool< this.opts.enableEvents = opts.enableEvents ?? true } - /** @inheritDoc */ + /** {@inheritDoc} */ public abstract get type (): PoolType - /** @inheritDoc */ + /** {@inheritDoc} */ public get numberOfRunningTasks (): number { return this.promiseMap.size } - /** @inheritDoc */ + /** {@inheritDoc} */ public getWorkerIndex (worker: Worker): number { return this.workers.indexOf(worker) } - /** @inheritDoc */ + /** {@inheritDoc} */ public getWorkerRunningTasks (worker: Worker): number | undefined { return this.workersTasksUsage.get(worker)?.running } - /** @inheritDoc */ + /** {@inheritDoc} */ public getWorkerAverageTasksRunTime (worker: Worker): number | undefined { return this.workersTasksUsage.get(worker)?.avgRunTime } - /** @inheritDoc */ + /** {@inheritDoc} */ public setWorkerChoiceStrategy ( workerChoiceStrategy: WorkerChoiceStrategy ): void { @@ -180,7 +180,7 @@ export abstract class AbstractPool< ) } - /** @inheritDoc */ + /** {@inheritDoc} */ public abstract get busy (): boolean protected internalGetBusyStatus (): boolean { @@ -190,7 +190,7 @@ export abstract class AbstractPool< ) } - /** @inheritDoc */ + /** {@inheritDoc} */ public findFreeWorker (): Worker | false { for (const worker of this.workers) { if (this.getWorkerRunningTasks(worker) === 0) { @@ -201,7 +201,7 @@ export abstract class AbstractPool< return false } - /** @inheritDoc */ + /** {@inheritDoc} */ public async execute (data: Data): Promise { // Configure worker to handle message with the specified task const worker = this.chooseWorker() @@ -216,7 +216,7 @@ export abstract class AbstractPool< return res } - /** @inheritDoc */ + /** {@inheritDoc} */ public async destroy (): Promise { await Promise.all(this.workers.map(worker => this.destroyWorker(worker))) } @@ -224,7 +224,7 @@ export abstract class AbstractPool< /** * Shutdowns given worker. * - * @param worker A worker within `workers`. + * @param worker - A worker within `workers`. */ protected abstract destroyWorker (worker: Worker): void | Promise @@ -245,7 +245,7 @@ export abstract class AbstractPool< * Hook executed before the worker task promise resolution. * Can be overridden. * - * @param worker The worker. + * @param worker - The worker. */ protected beforePromiseWorkerResponseHook (worker: Worker): void { this.increaseWorkerRunningTasks(worker) @@ -255,8 +255,8 @@ export abstract class AbstractPool< * Hook executed after the worker task promise resolution. * Can be overridden. * - * @param message The received message. - * @param promise The Promise response. + * @param message - The received message. + * @param promise - The Promise response. */ protected afterPromiseWorkerResponseHook ( message: MessageValue, @@ -270,7 +270,7 @@ export abstract class AbstractPool< /** * Removes the given worker from the pool. * - * @param worker The worker that will be removed. + * @param worker - The worker that will be removed. */ protected removeWorker (worker: Worker): void { // Clean worker from data structure @@ -292,8 +292,8 @@ export abstract class AbstractPool< /** * Sends a message to the given worker. * - * @param worker The worker which should receive the message. - * @param message The message. + * @param worker - The worker which should receive the message. + * @param message - The message. */ protected abstract sendToWorker ( worker: Worker, @@ -303,8 +303,8 @@ export abstract class AbstractPool< /** * Registers a listener callback on a given worker. * - * @param worker The worker which should register a listener. - * @param listener The message listener callback. + * @param worker - The worker which should register a listener. + * @param listener - The message listener callback. */ protected abstract registerWorkerMessageListener< Message extends Data | Response @@ -318,9 +318,9 @@ export abstract class AbstractPool< /** * Function that can be hooked up when a worker has been newly created and moved to the workers registry. * - * Can be used to update the `maxListeners` or binding the `main-worker`<->`worker` connection if not bind by default. + * Can be used to update the `maxListeners` or binding the `main-worker`\<-\>`worker` connection if not bind by default. * - * @param worker The newly created worker. + * @param worker - The newly created worker. */ protected abstract afterWorkerSetup (worker: Worker): void @@ -389,7 +389,7 @@ export abstract class AbstractPool< /** * Increases the number of tasks that the given worker has applied. * - * @param worker Worker which running tasks is increased. + * @param worker - Worker which running tasks is increased. */ private increaseWorkerRunningTasks (worker: Worker): void { this.stepWorkerRunningTasks(worker, 1) @@ -398,7 +398,7 @@ export abstract class AbstractPool< /** * Decreases the number of tasks that the given worker has applied. * - * @param worker Worker which running tasks is decreased. + * @param worker - Worker which running tasks is decreased. */ private decreaseWorkerRunningTasks (worker: Worker): void { this.stepWorkerRunningTasks(worker, -1) @@ -407,8 +407,8 @@ export abstract class AbstractPool< /** * Steps the number of tasks that the given worker has applied. * - * @param worker Worker which running tasks are stepped. - * @param step Number of running tasks step. + * @param worker - Worker which running tasks are stepped. + * @param step - Number of running tasks step. */ private stepWorkerRunningTasks (worker: Worker, step: number): void { if (this.checkWorkerTasksUsage(worker)) { @@ -421,8 +421,8 @@ export abstract class AbstractPool< /** * Steps the number of tasks that the given worker has run. * - * @param worker Worker which has run tasks. - * @param step Number of run tasks step. + * @param worker - Worker which has run tasks. + * @param step - Number of run tasks step. */ private stepWorkerRunTasks (worker: Worker, step: number): void { if (this.checkWorkerTasksUsage(worker)) { @@ -435,8 +435,8 @@ export abstract class AbstractPool< /** * Updates tasks runtime for the given worker. * - * @param worker Worker which run the task. - * @param taskRunTime Worker task runtime. + * @param worker - Worker which run the task. + * @param taskRunTime - Worker task runtime. */ private updateWorkerTasksRunTime ( worker: Worker, @@ -459,7 +459,7 @@ export abstract class AbstractPool< /** * Checks if the given worker is registered in the workers tasks usage map. * - * @param worker Worker to check. + * @param worker - Worker to check. * @returns `true` if the worker is registered in the workers tasks usage map. `false` otherwise. */ private checkWorkerTasksUsage (worker: Worker): boolean { @@ -473,7 +473,7 @@ export abstract class AbstractPool< /** * Initializes tasks usage statistics. * - * @param worker The worker. + * @param worker - The worker. */ private initWorkerTasksUsage (worker: Worker): void { this.workersTasksUsage.set(worker, { @@ -487,7 +487,7 @@ export abstract class AbstractPool< /** * Removes worker tasks usage statistics. * - * @param worker The worker. + * @param worker - The worker. */ private removeWorkerTasksUsage (worker: Worker): void { this.workersTasksUsage.delete(worker) @@ -496,7 +496,7 @@ export abstract class AbstractPool< /** * Resets worker tasks usage statistics. * - * @param worker The worker. + * @param worker - The worker. */ private resetWorkerTasksUsage (worker: Worker): void { this.removeWorkerTasksUsage(worker) diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index a90e5860..8b8c5185 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -8,8 +8,8 @@ import { FixedClusterPool } from './fixed' * This cluster pool creates new workers when the others are busy, up to the maximum number of workers. * When the maximum number of workers is reached, an event is emitted. If you want to listen to this event, use the pool's `emitter`. * - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. * @author [Christopher Quadflieg](https://github.com/Shinigami92) * @since 2.0.0 */ @@ -20,10 +20,10 @@ export class DynamicClusterPool< /** * Constructs a new poolifier dynamic cluster pool. * - * @param min Minimum number of workers which are always active. - * @param max Maximum number of workers that can be created by this pool. - * @param filePath Path to an implementation of a `ClusterWorker` file, which can be relative or absolute. - * @param opts Options for this dynamic cluster pool. + * @param min - Minimum number of workers which are always active. + * @param max - Maximum number of workers that can be created by this pool. + * @param filePath - Path to an implementation of a `ClusterWorker` file, which can be relative or absolute. + * @param opts - Options for this dynamic cluster pool. */ public constructor ( min: number, @@ -34,12 +34,12 @@ export class DynamicClusterPool< super(min, filePath, opts) } - /** @inheritDoc */ + /** {@inheritDoc} */ public get type (): PoolType { return PoolType.DYNAMIC } - /** @inheritDoc */ + /** {@inheritDoc} */ public get busy (): boolean { return this.workers.length === this.max } diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index a58dfb6f..2e89b323 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -31,8 +31,8 @@ export interface ClusterPoolOptions extends PoolOptions { * * This pool selects the workers in a round robin fashion. * - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. * @author [Christopher Quadflieg](https://github.com/Shinigami92) * @since 2.0.0 */ @@ -43,9 +43,9 @@ export class FixedClusterPool< /** * Constructs a new poolifier fixed cluster pool. * - * @param numberOfWorkers Number of workers for this pool. - * @param filePath Path to an implementation of a `ClusterWorker` file, which can be relative or absolute. - * @param opts Options for this fixed cluster pool. + * @param numberOfWorkers - Number of workers for this pool. + * @param filePath - Path to an implementation of a `ClusterWorker` file, which can be relative or absolute. + * @param opts - Options for this fixed cluster pool. */ public constructor ( numberOfWorkers: number, @@ -55,28 +55,28 @@ export class FixedClusterPool< super(numberOfWorkers, filePath, opts) } - /** @inheritDoc */ + /** {@inheritDoc} */ protected setupHook (): void { cluster.setupPrimary({ ...this.opts.settings, exec: this.filePath }) } - /** @inheritDoc */ + /** {@inheritDoc} */ protected isMain (): boolean { return cluster.isPrimary } - /** @inheritDoc */ + /** {@inheritDoc} */ public destroyWorker (worker: Worker): void { this.sendToWorker(worker, { kill: 1 }) worker.kill() } - /** @inheritDoc */ + /** {@inheritDoc} */ protected sendToWorker (worker: Worker, message: MessageValue): void { worker.send(message) } - /** @inheritDoc */ + /** {@inheritDoc} */ public registerWorkerMessageListener( worker: Worker, listener: (message: MessageValue) => void @@ -84,23 +84,23 @@ export class FixedClusterPool< worker.on('message', listener) } - /** @inheritDoc */ + /** {@inheritDoc} */ protected createWorker (): Worker { return cluster.fork(this.opts.env) } - /** @inheritDoc */ + /** {@inheritDoc} */ protected afterWorkerSetup (worker: Worker): void { // Listen to worker messages. this.registerWorkerMessageListener(worker, super.workerListener()) } - /** @inheritDoc */ + /** {@inheritDoc} */ public get type (): PoolType { return PoolType.FIXED } - /** @inheritDoc */ + /** {@inheritDoc} */ public get busy (): boolean { return this.internalGetBusyStatus() } diff --git a/src/pools/pool-internal.ts b/src/pools/pool-internal.ts index 0c2454f8..e0d0534f 100644 --- a/src/pools/pool-internal.ts +++ b/src/pools/pool-internal.ts @@ -22,9 +22,9 @@ export interface TasksUsage { /** * Internal contract definition for a poolifier pool. * - * @template Worker Type of worker which manages this pool. - * @template Data Type of data sent to the worker. - * @template Response Type of response of execution. + * @typeParam Worker - Type of worker which manages this pool. + * @typeParam Data - Type of data sent to the worker. + * @typeParam Response - Type of response of execution. */ export interface IPoolInternal< Worker extends IPoolWorker, @@ -77,7 +77,7 @@ export interface IPoolInternal< /** * Gets worker index. * - * @param worker The worker. + * @param worker - The worker. * @returns The worker index. */ getWorkerIndex: (worker: Worker) => number @@ -85,7 +85,7 @@ export interface IPoolInternal< /** * Gets worker running tasks. * - * @param worker The worker. + * @param worker - The worker. * @returns The number of tasks currently running on the worker. */ getWorkerRunningTasks: (worker: Worker) => number | undefined @@ -93,7 +93,7 @@ export interface IPoolInternal< /** * Gets worker average tasks runtime. * - * @param worker The worker. + * @param worker - The worker. * @returns The average tasks runtime on the worker. */ getWorkerAverageTasksRunTime: (worker: Worker) => number | undefined diff --git a/src/pools/pool-worker.ts b/src/pools/pool-worker.ts index 0d4d12fe..e371e9c1 100644 --- a/src/pools/pool-worker.ts +++ b/src/pools/pool-worker.ts @@ -25,8 +25,8 @@ export interface IPoolWorker { /** * Register an event listener. * - * @param event The event. - * @param handler The event listener. + * @param event - The event. + * @param handler - The event listener. */ on: ((event: 'message', handler: MessageHandler) => void) & ((event: 'error', handler: ErrorHandler) => void) & @@ -35,8 +35,8 @@ export interface IPoolWorker { /** * Register a listener to the exit event that will only performed once. * - * @param event `'exit'`. - * @param handler The exit handler. + * @param event - `'exit'`. + * @param handler - The exit handler. */ once: (event: 'exit', handler: ExitHandler) => void } diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 2ce311f7..dbbb5969 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -39,7 +39,7 @@ export interface PoolOptions { /** * Pool events emission. * - * @default true + * @defaultValue true */ enableEvents?: boolean } @@ -47,8 +47,8 @@ export interface PoolOptions { /** * Contract definition for a poolifier pool. * - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. */ export interface IPool { /** @@ -62,7 +62,7 @@ export interface IPool { /** * Performs the task specified in the constructor with the data parameter. * - * @param data The input for the specified task. This can only be serializable data. + * @param data - The input for the specified task. This can only be serializable data. * @returns Promise that will be resolved when the task is successfully completed. */ execute: (data: Data) => Promise @@ -73,7 +73,7 @@ export interface IPool { /** * Sets the worker choice strategy in this pool. * - * @param workerChoiceStrategy The worker choice strategy. + * @param workerChoiceStrategy - The worker choice strategy. */ setWorkerChoiceStrategy: (workerChoiceStrategy: WorkerChoiceStrategy) => void } diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index 3ba59b42..314c13c0 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -9,18 +9,18 @@ import type { /** * Abstract worker choice strategy class. * - * @template Worker Type of worker which manages the strategy. - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Worker - Type of worker which manages the strategy. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. */ export abstract class AbstractWorkerChoiceStrategy< Worker extends IPoolWorker, Data, Response > implements IWorkerChoiceStrategy { - /** @inheritDoc */ + /** {@inheritDoc} */ public readonly isDynamicPool: boolean = this.pool.type === PoolType.DYNAMIC - /** @inheritDoc */ + /** {@inheritDoc} */ public requiredStatistics: RequiredStatistics = { runTime: false } @@ -28,15 +28,15 @@ export abstract class AbstractWorkerChoiceStrategy< /** * Constructs a worker choice strategy attached to the pool. * - * @param pool The pool instance. + * @param pool - The pool instance. */ public constructor ( protected readonly pool: IPoolInternal ) {} - /** @inheritDoc */ + /** {@inheritDoc} */ public abstract reset (): boolean - /** @inheritDoc */ + /** {@inheritDoc} */ public abstract choose (): Worker } diff --git a/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts b/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts index 6f73129e..5f07d607 100644 --- a/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts @@ -11,9 +11,9 @@ import { getWorkerChoiceStrategy } from './selection-strategies-utils' /** * Selects the next worker for dynamic pool. * - * @template Worker Type of worker which manages the strategy. - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Worker - Type of worker which manages the strategy. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. */ export class DynamicPoolWorkerChoiceStrategy< Worker extends IPoolWorker, @@ -25,9 +25,9 @@ export class DynamicPoolWorkerChoiceStrategy< /** * Constructs a worker choice strategy for dynamic pool. * - * @param pool The pool instance. - * @param createDynamicallyWorkerCallback The worker creation callback for dynamic pool. - * @param workerChoiceStrategy The worker choice strategy when the pull is busy. + * @param pool - The pool instance. + * @param createDynamicallyWorkerCallback - The worker creation callback for dynamic pool. + * @param workerChoiceStrategy - The worker choice strategy when the pull is busy. */ public constructor ( pool: IPoolInternal, @@ -42,12 +42,12 @@ export class DynamicPoolWorkerChoiceStrategy< this.requiredStatistics = this.workerChoiceStrategy.requiredStatistics } - /** @inheritDoc */ + /** {@inheritDoc} */ public reset (): boolean { return this.workerChoiceStrategy.reset() } - /** @inheritDoc */ + /** {@inheritDoc} */ public choose (): Worker { const freeWorker = this.pool.findFreeWorker() if (freeWorker !== false) { diff --git a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts index 2fd43d7a..00ed1c90 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -14,16 +14,16 @@ interface WorkerVirtualTaskTimestamp { * Selects the next worker with a fair share scheduling algorithm. * Loosely modeled after the fair queueing algorithm: https://en.wikipedia.org/wiki/Fair_queuing. * - * @template Worker Type of worker which manages the strategy. - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Worker - Type of worker which manages the strategy. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. */ export class FairShareWorkerChoiceStrategy< Worker extends IPoolWorker, Data, Response > extends AbstractWorkerChoiceStrategy { - /** @inheritDoc */ + /** {@inheritDoc} */ public readonly requiredStatistics: RequiredStatistics = { runTime: true } @@ -36,13 +36,13 @@ export class FairShareWorkerChoiceStrategy< WorkerVirtualTaskTimestamp > = new Map() - /** @inheritDoc */ + /** {@inheritDoc} */ public reset (): boolean { this.workerLastVirtualTaskTimestamp.clear() return true } - /** @inheritDoc */ + /** {@inheritDoc} */ public choose (): Worker { let minWorkerVirtualTaskEndTimestamp = Infinity let chosenWorker!: Worker @@ -63,7 +63,7 @@ export class FairShareWorkerChoiceStrategy< /** * Computes worker last virtual task timestamp. * - * @param worker The worker. + * @param worker - The worker. */ private computeWorkerLastVirtualTaskTimestamp (worker: Worker): void { const workerVirtualTaskStartTimestamp = Math.max( diff --git a/src/pools/selection-strategies/less-recently-used-worker-choice-strategy.ts b/src/pools/selection-strategies/less-recently-used-worker-choice-strategy.ts index 2bfbb15b..e62d9cdf 100644 --- a/src/pools/selection-strategies/less-recently-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/less-recently-used-worker-choice-strategy.ts @@ -4,21 +4,21 @@ import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' /** * Selects the less recently used worker. * - * @template Worker Type of worker which manages the strategy. - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Worker - Type of worker which manages the strategy. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. */ export class LessRecentlyUsedWorkerChoiceStrategy< Worker extends IPoolWorker, Data, Response > extends AbstractWorkerChoiceStrategy { - /** @inheritDoc */ + /** {@inheritDoc} */ public reset (): boolean { return true } - /** @inheritDoc */ + /** {@inheritDoc} */ public choose (): Worker { let minNumberOfRunningTasks = Infinity // A worker is always found because it picks the one with fewer tasks diff --git a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts index 0a9fbb7b..76cdd4ab 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -4,9 +4,9 @@ import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' /** * Selects the next worker in a round robin fashion. * - * @template Worker Type of worker which manages the strategy. - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Worker - Type of worker which manages the strategy. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. */ export class RoundRobinWorkerChoiceStrategy< Worker extends IPoolWorker, @@ -18,13 +18,13 @@ export class RoundRobinWorkerChoiceStrategy< */ private nextWorkerIndex: number = 0 - /** @inheritDoc */ + /** {@inheritDoc} */ public reset (): boolean { this.nextWorkerIndex = 0 return true } - /** @inheritDoc */ + /** {@inheritDoc} */ public choose (): Worker { const chosenWorker = this.pool.workers[this.nextWorkerIndex] this.nextWorkerIndex = diff --git a/src/pools/selection-strategies/selection-strategies-types.ts b/src/pools/selection-strategies/selection-strategies-types.ts index 21e4129e..3e7c3427 100644 --- a/src/pools/selection-strategies/selection-strategies-types.ts +++ b/src/pools/selection-strategies/selection-strategies-types.ts @@ -37,7 +37,7 @@ export interface RequiredStatistics { /** * Worker choice strategy interface. * - * @template Worker Type of worker which manages the strategy. + * @typeParam Worker - Type of worker which manages the strategy. */ export interface IWorkerChoiceStrategy { /** diff --git a/src/pools/selection-strategies/selection-strategies-utils.ts b/src/pools/selection-strategies/selection-strategies-utils.ts index 70735c08..4c0fea61 100644 --- a/src/pools/selection-strategies/selection-strategies-utils.ts +++ b/src/pools/selection-strategies/selection-strategies-utils.ts @@ -13,8 +13,8 @@ import { WeightedRoundRobinWorkerChoiceStrategy } from './weighted-round-robin-w /** * Gets the worker choice strategy instance. * - * @param pool The pool instance. - * @param workerChoiceStrategy The worker choice strategy. + * @param pool - The pool instance. + * @param workerChoiceStrategy - The worker choice strategy. * @returns The worker choice strategy instance. */ export function getWorkerChoiceStrategy< diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 9bd5a07b..2b7cd942 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -16,16 +16,16 @@ interface TaskRunTime { * Selects the next worker with a weighted round robin scheduling algorithm. * Loosely modeled after the weighted round robin queueing algorithm: https://en.wikipedia.org/wiki/Weighted_round_robin. * - * @template Worker Type of worker which manages the strategy. - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Worker - Type of worker which manages the strategy. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. */ export class WeightedRoundRobinWorkerChoiceStrategy< Worker extends IPoolWorker, Data, Response > extends AbstractWorkerChoiceStrategy { - /** @inheritDoc */ + /** {@inheritDoc} */ public readonly requiredStatistics: RequiredStatistics = { runTime: true } @@ -49,7 +49,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy< /** * Constructs a worker choice strategy that selects with a weighted round robin scheduling algorithm. * - * @param pool The pool instance. + * @param pool - The pool instance. */ public constructor (pool: IPoolInternal) { super(pool) @@ -57,7 +57,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy< this.initWorkersTaskRunTime() } - /** @inheritDoc */ + /** {@inheritDoc} */ public reset (): boolean { this.currentWorkerIndex = 0 this.workersTaskRunTime.clear() @@ -65,7 +65,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy< return true } - /** @inheritDoc */ + /** {@inheritDoc} */ public choose (): Worker { const chosenWorker = this.pool.workers[this.currentWorkerIndex] if (this.isDynamicPool && !this.workersTaskRunTime.has(chosenWorker)) { diff --git a/src/pools/selection-strategies/worker-choice-strategy-context.ts b/src/pools/selection-strategies/worker-choice-strategy-context.ts index 42e6735e..1bba1a55 100644 --- a/src/pools/selection-strategies/worker-choice-strategy-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategy-context.ts @@ -12,9 +12,9 @@ import { getWorkerChoiceStrategy } from './selection-strategies-utils' /** * The worker choice strategy context. * - * @template Worker Type of worker. - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Worker - Type of worker. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. */ export class WorkerChoiceStrategyContext< Worker extends IPoolWorker, @@ -26,9 +26,9 @@ export class WorkerChoiceStrategyContext< /** * Worker choice strategy context constructor. * - * @param pool The pool instance. - * @param createDynamicallyWorkerCallback The worker creation callback for dynamic pool. - * @param workerChoiceStrategy The worker choice strategy. + * @param pool - The pool instance. + * @param createDynamicallyWorkerCallback - The worker creation callback for dynamic pool. + * @param workerChoiceStrategy - The worker choice strategy. */ public constructor ( private readonly pool: IPoolInternal, @@ -41,7 +41,7 @@ export class WorkerChoiceStrategyContext< /** * Gets the worker choice strategy instance specific to the pool type. * - * @param workerChoiceStrategy The worker choice strategy. + * @param workerChoiceStrategy - The worker choice strategy. * @returns The worker choice strategy instance for the pool type. */ private getPoolWorkerChoiceStrategy ( @@ -69,7 +69,7 @@ export class WorkerChoiceStrategyContext< /** * Sets the worker choice strategy to use in the context. * - * @param workerChoiceStrategy The worker choice strategy to set. + * @param workerChoiceStrategy - The worker choice strategy to set. */ public setWorkerChoiceStrategy ( workerChoiceStrategy: WorkerChoiceStrategy diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index a6cc209a..19cb9fbf 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -9,8 +9,8 @@ import { FixedThreadPool } from './fixed' * This thread pool creates new threads when the others are busy, up to the maximum number of threads. * When the maximum number of threads is reached, an event is emitted. If you want to listen to this event, use the pool's `emitter`. * - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. * @author [Alessandro Pio Ardizio](https://github.com/pioardi) * @since 0.0.1 */ @@ -21,10 +21,10 @@ export class DynamicThreadPool< /** * Constructs a new poolifier dynamic thread pool. * - * @param min Minimum number of threads which are always active. - * @param max Maximum number of threads that can be created by this pool. - * @param filePath Path to an implementation of a `ThreadWorker` file, which can be relative or absolute. - * @param opts Options for this dynamic thread pool. + * @param min - Minimum number of threads which are always active. + * @param max - Maximum number of threads that can be created by this pool. + * @param filePath - Path to an implementation of a `ThreadWorker` file, which can be relative or absolute. + * @param opts - Options for this dynamic thread pool. */ public constructor ( min: number, @@ -35,12 +35,12 @@ export class DynamicThreadPool< super(min, filePath, opts) } - /** @inheritDoc */ + /** {@inheritDoc} */ public get type (): PoolType { return PoolType.DYNAMIC } - /** @inheritDoc */ + /** {@inheritDoc} */ public get busy (): boolean { return this.workers.length === this.max } diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index a8161f67..13a280b5 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -16,8 +16,8 @@ export type ThreadWorkerWithMessageChannel = Worker & Draft * * This pool selects the threads in a round robin fashion. * - * @template Data Type of data sent to the worker. This can only be serializable data. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of response of execution. This can only be serializable data. * @author [Alessandro Pio Ardizio](https://github.com/pioardi) * @since 0.0.1 */ @@ -28,9 +28,9 @@ export class FixedThreadPool< /** * Constructs a new poolifier fixed thread pool. * - * @param numberOfThreads Number of threads for this pool. - * @param filePath Path to an implementation of a `ThreadWorker` file, which can be relative or absolute. - * @param opts Options for this fixed thread pool. + * @param numberOfThreads - Number of threads for this pool. + * @param filePath - Path to an implementation of a `ThreadWorker` file, which can be relative or absolute. + * @param opts - Options for this fixed thread pool. */ public constructor ( numberOfThreads: number, @@ -40,12 +40,12 @@ export class FixedThreadPool< super(numberOfThreads, filePath, opts) } - /** @inheritDoc */ + /** {@inheritDoc} */ protected isMain (): boolean { return isMainThread } - /** @inheritDoc */ + /** {@inheritDoc} */ public async destroyWorker ( worker: ThreadWorkerWithMessageChannel ): Promise { @@ -53,7 +53,7 @@ export class FixedThreadPool< await worker.terminate() } - /** @inheritDoc */ + /** {@inheritDoc} */ protected sendToWorker ( worker: ThreadWorkerWithMessageChannel, message: MessageValue @@ -61,7 +61,7 @@ export class FixedThreadPool< worker.postMessage(message) } - /** @inheritDoc */ + /** {@inheritDoc} */ public registerWorkerMessageListener( messageChannel: ThreadWorkerWithMessageChannel, listener: (message: MessageValue) => void @@ -69,14 +69,14 @@ export class FixedThreadPool< messageChannel.port2?.on('message', listener) } - /** @inheritDoc */ + /** {@inheritDoc} */ protected createWorker (): ThreadWorkerWithMessageChannel { return new Worker(this.filePath, { env: SHARE_ENV }) } - /** @inheritDoc */ + /** {@inheritDoc} */ protected afterWorkerSetup (worker: ThreadWorkerWithMessageChannel): void { const { port1, port2 } = new MessageChannel() worker.postMessage({ parent: port1 }, [port1]) @@ -86,12 +86,12 @@ export class FixedThreadPool< this.registerWorkerMessageListener(worker, super.workerListener()) } - /** @inheritDoc */ + /** {@inheritDoc} */ public get type (): PoolType { return PoolType.FIXED } - /** @inheritDoc */ + /** {@inheritDoc} */ public get busy (): boolean { return this.internalGetBusyStatus() } diff --git a/src/utility-types.ts b/src/utility-types.ts index 7bcd076c..2d142f86 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -46,8 +46,8 @@ export interface MessageValue< /** * An object holding the worker that will be used to resolve/rejects the promise later on. * - * @template Worker Type of worker. - * @template Response Type of response of execution. This can only be serializable data. + * @typeParam Worker - Type of worker. + * @typeParam Response - Type of response of execution. This can only be serializable data. */ export interface PromiseWorkerResponseWrapper< Worker extends IPoolWorker, diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 84699459..3a81e0f8 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -12,9 +12,9 @@ const DEFAULT_KILL_BEHAVIOR: KillBehavior = KillBehaviors.SOFT /** * Base class that implements some shared logic for all poolifier workers. * - * @template MainWorker Type of main worker. - * @template Data Type of data this worker receives from pool's execution. This can only be serializable data. - * @template Response Type of response the worker sends back to the main worker. This can only be serializable data. + * @typeParam MainWorker - Type of main worker. + * @typeParam Data - Type of data this worker receives from pool's execution. This can only be serializable data. + * @typeParam Response - Type of response the worker sends back to the main worker. This can only be serializable data. */ export abstract class AbstractWorker< MainWorker extends Worker | MessagePort, @@ -36,11 +36,11 @@ export abstract class AbstractWorker< /** * Constructs a new poolifier worker. * - * @param type The type of async event. - * @param isMain Whether this is the main worker or not. - * @param fn Function processed by the worker when the pool's `execution` function is invoked. - * @param mainWorker Reference to main worker. - * @param opts Options for the worker. + * @param type - The type of async event. + * @param isMain - Whether this is the main worker or not. + * @param fn - Function processed by the worker when the pool's `execution` function is invoked. + * @param mainWorker - Reference to main worker. + * @param opts - Options for the worker. */ public constructor ( type: string, @@ -110,7 +110,7 @@ export abstract class AbstractWorker< /** * Checks if the `fn` parameter is passed to the constructor. * - * @param fn The function that should be defined. + * @param fn - The function that should be defined. */ private checkFunctionInput (fn: (data: Data) => Response): void { if (fn == null) throw new Error('fn parameter is mandatory') @@ -134,7 +134,7 @@ export abstract class AbstractWorker< /** * Sends a message to the main worker. * - * @param message The response message. + * @param message - The response message. */ protected abstract sendToMainWorker (message: MessageValue): void @@ -153,7 +153,7 @@ export abstract class AbstractWorker< /** * Handles an error and convert it to a string so it can be sent back to the main worker. * - * @param e The error raised by the worker. + * @param e - The error raised by the worker. * @returns Message of the error. */ protected handleError (e: Error | string): string { @@ -163,8 +163,8 @@ export abstract class AbstractWorker< /** * Runs the given function synchronously. * - * @param fn Function that will be executed. - * @param value Input data for the given function. + * @param fn - Function that will be executed. + * @param value - Input data for the given function. */ protected run ( fn: (data?: Data) => Response, @@ -186,8 +186,8 @@ export abstract class AbstractWorker< /** * Runs the given function asynchronously. * - * @param fn Function that will be executed. - * @param value Input data for the given function. + * @param fn - Function that will be executed. + * @param value - Input data for the given function. */ protected runAsync ( fn: (data?: Data) => Promise, diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index 19bfa4e5..4f5fbb6b 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -13,8 +13,8 @@ import type { WorkerOptions } from './worker-options' * If you use a `DynamicClusterPool` the extra workers that were created will be terminated, * but the minimum number of workers will be guaranteed. * - * @template Data Type of data this worker receives from pool's execution. This can only be serializable data. - * @template Response Type of response the worker sends back to the main worker. This can only be serializable data. + * @typeParam Data - Type of data this worker receives from pool's execution. This can only be serializable data. + * @typeParam Response - Type of response the worker sends back to the main worker. This can only be serializable data. * @author [Christopher Quadflieg](https://github.com/Shinigami92) * @since 2.0.0 */ @@ -25,8 +25,8 @@ export class ClusterWorker< /** * Constructs a new poolifier cluster worker. * - * @param fn Function processed by the worker when the pool's `execution` function is invoked. - * @param opts Options for the worker. + * @param fn - Function processed by the worker when the pool's `execution` function is invoked. + * @param opts - Options for the worker. */ public constructor (fn: (data: Data) => Response, opts: WorkerOptions = {}) { super( @@ -38,12 +38,12 @@ export class ClusterWorker< ) } - /** @inheritDoc */ + /** {@inheritDoc} */ protected sendToMainWorker (message: MessageValue): void { this.getMainWorker().send(message) } - /** @inheritDoc */ + /** {@inheritDoc} */ protected handleError (e: Error | string): string { return e instanceof Error ? e.message : e } diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index 20141e44..a8424fbf 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -13,8 +13,8 @@ import type { WorkerOptions } from './worker-options' * If you use a `DynamicThreadPool` the extra workers that were created will be terminated, * but the minimum number of workers will be guaranteed. * - * @template Data Type of data this worker receives from pool's execution. This can only be serializable data. - * @template Response Type of response the worker sends back to the main thread. This can only be serializable data. + * @typeParam Data - Type of data this worker receives from pool's execution. This can only be serializable data. + * @typeParam Response - Type of response the worker sends back to the main thread. This can only be serializable data. * @author [Alessandro Pio Ardizio](https://github.com/pioardi) * @since 0.0.1 */ @@ -25,14 +25,14 @@ export class ThreadWorker< /** * Constructs a new poolifier thread worker. * - * @param fn Function processed by the worker when the pool's `execution` function is invoked. - * @param opts Options for the worker. + * @param fn - Function processed by the worker when the pool's `execution` function is invoked. + * @param opts - Options for the worker. */ public constructor (fn: (data: Data) => Response, opts: WorkerOptions = {}) { super('worker-thread-pool:poolifier', isMainThread, fn, parentPort, opts) } - /** @inheritDoc */ + /** {@inheritDoc} */ protected sendToMainWorker (message: MessageValue): void { this.getMainWorker().postMessage(message) } diff --git a/src/worker/worker-options.ts b/src/worker/worker-options.ts index c9a3cdfa..290914f1 100644 --- a/src/worker/worker-options.ts +++ b/src/worker/worker-options.ts @@ -20,9 +20,9 @@ export type KillBehavior = keyof typeof KillBehaviors /** * Detects whether the given value is a kill behavior or not. * - * @template KB Which specific KillBehavior to test against. - * @param killBehavior Which kind of kill behavior to detect. - * @param value Any value. + * @typeParam KB - Which specific KillBehavior to test against. + * @param killBehavior - Which kind of kill behavior to detect. + * @param value - Any value. * @returns `true` if `value` was strictly equals to `killBehavior`, otherwise `false`. */ export function isKillBehavior ( @@ -46,13 +46,13 @@ export interface WorkerOptions { * 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 60000 ms + * @defaultValue 60000 ms */ maxInactiveTime?: number /** * Whether your worker will perform asynchronous or not. * - * @default false + * @defaultValue false */ async?: boolean /** @@ -63,7 +63,7 @@ export interface WorkerOptions { * * This option only apply to the newly created workers. * - * @default KillBehaviors.SOFT + * @defaultValue KillBehaviors.SOFT */ killBehavior?: KillBehavior } -- 2.34.1