X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fthread%2Fdynamic.ts;h=39867e6c0e72dd52a040705dbfe7cfb0182089de;hb=90bd5e4759bd31cc25b6f42e88d07ed05b969cec;hp=4a2fd5e807f1bf992155bc155a89d956616ef589;hpb=3ec964d666b2ffa57b57a37a29542a727fc55ee6;p=poolifier.git diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index 4a2fd5e8..39867e6c 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -1,8 +1,8 @@ import type { JSONValue } from '../../utility-types' +import { isKillBehavior, KillBehaviors } from '../../worker/worker-options' import type { PoolOptions } from '../abstract-pool' import type { ThreadWorkerWithMessageChannel } from './fixed' import { FixedThreadPool } from './fixed' -import { killBehaviorTypes } from '../../worker/worker-options' /** * A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads. @@ -25,16 +25,16 @@ export class DynamicThreadPool< * * @param min Minimum number of threads which are always active. * @param max Maximum number of threads that can be created by this pool. - * @param filename Path to an implementation of a `ThreadWorker` file, which can be relative or absolute. - * @param opts Options for this fixed thread pool. Default: `{ maxTasks: 1000 }` + * @param filePath Path to an implementation of a `ThreadWorker` file, which can be relative or absolute. + * @param opts Options for this dynamic thread pool. Default: `{ maxTasks: 1000 }` */ public constructor ( min: number, public readonly max: number, - filename: string, + filePath: string, opts: PoolOptions = { maxTasks: 1000 } ) { - super(min, filename, opts) + super(min, filePath, opts) } /** @@ -63,10 +63,11 @@ export class DynamicThreadPool< const workerCreated = this.createAndSetupWorker() this.registerWorkerMessageListener(workerCreated, message => { const tasksInProgress = this.tasks.get(workerCreated) - const isKillBehaviorOptionHard = message.kill === killBehaviorTypes.HARD - if (isKillBehaviorOptionHard || tasksInProgress === 0) { + if ( + isKillBehavior(KillBehaviors.HARD, message.kill) || + tasksInProgress === 0 + ) { // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime) - this.sendToWorker(workerCreated, { kill: 1 }) void this.destroyWorker(workerCreated) } })