X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fhttp-server-pool%2Ffastify-worker_threads%2Fsrc%2Ffastify-poolifier.ts;h=c031d287d34a640b368839fe8ef6936d47a6cf9a;hb=937d524da3a5cce4795b85ddd1c430f0d184f731;hp=38c808a0cc2b223239f4ad78a7fb48ad20c8b049;hpb=5daad283d56413b7287cca894637a35e51a1222c;p=poolifier.git diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts index 38c808a0..c031d287 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts @@ -1,11 +1,13 @@ -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 { - type FastifyPoolifierOptions, - type WorkerData, - type WorkerResponse +import { availableParallelism, DynamicThreadPool } from 'poolifier' + +import type { + FastifyPoolifierOptions, + WorkerData, + WorkerResponse } from './types.js' const fastifyPoolifierPlugin: FastifyPluginCallback = ( @@ -20,11 +22,12 @@ const fastifyPoolifierPlugin: FastifyPluginCallback = ( }, ...options } + const { workerFile, minWorkers, maxWorkers, ...poolOptions } = options const pool = new DynamicThreadPool( - options.minWorkers as number, - options.maxWorkers as number, - options.workerFile, - options + minWorkers!, + maxWorkers!, + workerFile, + poolOptions ) if (!fastify.hasDecorator('pool')) { fastify.decorate('pool', pool) @@ -35,15 +38,10 @@ const fastifyPoolifierPlugin: FastifyPluginCallback = ( async ( data?: WorkerData, name?: string, - transferList?: TransferListItem[] + transferList?: readonly TransferListItem[] ): Promise => await pool.execute(data, name, transferList) ) } - if (!fastify.hasDecorator('listTaskFunctions')) { - fastify.decorate('listTaskFunctions', (): string[] => - pool.listTaskFunctions() - ) - } done() }