fix: fix possible null exception at handling task execution response
[poolifier.git] / src / pools / thread / fixed.ts
index 28f8fceba679e5f9053820b8436583caf69f20af..197830279be020e45741fb00930bb82ffcc12ea3 100644 (file)
@@ -1,10 +1,8 @@
 import {
   type MessageChannel,
   type MessagePort,
-  SHARE_ENV,
   type TransferListItem,
-  Worker,
-  type WorkerOptions,
+  type Worker,
   isMainThread
 } from 'node:worker_threads'
 import type { MessageValue } from '../../utility-types'
@@ -12,18 +10,6 @@ import { AbstractPool } from '../abstract-pool'
 import { type PoolOptions, type PoolType, PoolTypes } from '../pool'
 import { type WorkerType, WorkerTypes } from '../worker'
 
-/**
- * Options for a poolifier thread pool.
- */
-export interface ThreadPoolOptions extends PoolOptions<Worker> {
-  /**
-   * Worker options.
-   *
-   * @see https://nodejs.org/api/worker_threads.html#new-workerfilename-options
-   */
-  workerOptions?: WorkerOptions
-}
-
 /**
  * A thread pool with a fixed number of threads.
  *
@@ -46,7 +32,7 @@ export class FixedThreadPool<
   public constructor (
     numberOfThreads: number,
     filePath: string,
-    protected readonly opts: ThreadPoolOptions = {}
+    protected readonly opts: PoolOptions<Worker> = {}
   ) {
     super(numberOfThreads, filePath, opts)
   }
@@ -56,25 +42,6 @@ export class FixedThreadPool<
     return isMainThread
   }
 
-  /** @inheritDoc */
-  protected async destroyWorkerNode (workerNodeKey: number): Promise<void> {
-    this.flagWorkerNodeAsNotReady(workerNodeKey)
-    this.flushTasksQueue(workerNodeKey)
-    // FIXME: wait for tasks to be finished
-    const workerNode = this.workerNodes[workerNodeKey]
-    const worker = workerNode.worker
-    const waitWorkerExit = new Promise<void>(resolve => {
-      worker.once('exit', () => {
-        resolve()
-      })
-    })
-    await this.sendKillMessageToWorker(workerNodeKey)
-    workerNode.closeChannel()
-    workerNode.removeAllListeners()
-    await worker.terminate()
-    await waitWorkerExit
-  }
-
   /** @inheritDoc */
   protected sendToWorker (
     workerNodeKey: number,
@@ -135,14 +102,6 @@ export class FixedThreadPool<
     )
   }
 
-  /** @inheritDoc */
-  protected createWorker (): Worker {
-    return new Worker(this.filePath, {
-      env: SHARE_ENV,
-      ...this.opts.workerOptions
-    })
-  }
-
   /** @inheritDoc */
   protected get type (): PoolType {
     return PoolTypes.fixed