Merge dependabot/npm_and_yarn/examples/typescript/websocket-server-pool/ws-cluster...
[poolifier.git] / examples / typescript / http-server-pool / fastify-hybrid / src / fastify-poolifier.ts
index 6e3a1dbfec643759ef30aecfd767e5f9d1c40e02..79d24dc61fe0a3f47a25d4e5fb5ddeb5880e2a2a 100644 (file)
@@ -1,7 +1,9 @@
-import type { TransferListItem } from 'worker_threads'
-import { DynamicThreadPool, availableParallelism } from 'poolifier'
-import { type FastifyPluginCallback } from 'fastify'
+import type { TransferListItem } from 'node:worker_threads'
+
+import type { FastifyPluginCallback } from 'fastify'
 import fp from 'fastify-plugin'
+import { availableParallelism, DynamicThreadPool } from 'poolifier'
+
 import {
   type FastifyPoolifierOptions,
   type ThreadWorkerData,
@@ -20,11 +22,12 @@ const fastifyPoolifierPlugin: FastifyPluginCallback<FastifyPoolifierOptions> = (
     },
     ...options
   }
+  const { workerFile, minWorkers, maxWorkers, ...poolOptions } = options
   const pool = new DynamicThreadPool<ThreadWorkerData, ThreadWorkerResponse>(
-    options.minWorkers as number,
-    options.maxWorkers as number,
-    options.workerFile,
-    options
+    minWorkers!,
+    maxWorkers!,
+    workerFile,
+    poolOptions
   )
   if (!fastify.hasDecorator('pool')) {
     fastify.decorate('pool', pool)