Only allow primitive JSON for transfer between worker and main worker (#128)
[poolifier.git] / src / pools / thread / fixed.ts
index bed8f3a7dba8ae87ed6085df040723a93eb0e739..badca517585d346072debabc0c306253a513c08c 100644 (file)
@@ -1,5 +1,5 @@
 import { isMainThread, MessageChannel, SHARE_ENV, Worker } from 'worker_threads'
-import type { Draft, MessageValue } from '../../utility-types'
+import type { Draft, JSONValue, MessageValue } from '../../utility-types'
 import type { PoolOptions } from '../abstract-pool'
 import { AbstractPool } from '../abstract-pool'
 
@@ -13,12 +13,10 @@ export type ThreadWorkerWithMessageChannel = Worker & Draft<MessageChannel>
  * @author [Alessandro Pio Ardizio](https://github.com/pioardi)
  * @since 0.0.1
  */
-// eslint-disable-next-line @typescript-eslint/no-explicit-any
-export class FixedThreadPool<Data = any, Response = any> extends AbstractPool<
-  ThreadWorkerWithMessageChannel,
-  Data,
-  Response
-> {
+export class FixedThreadPool<
+  Data extends JSONValue = JSONValue,
+  Response extends JSONValue = JSONValue
+> extends AbstractPool<ThreadWorkerWithMessageChannel, Data, Response> {
   /**
    * @param numThreads Num of threads for this worker pool.
    * @param filePath A file path with implementation of `ThreadWorker` class, relative path is fine.