1 import { DynamicThreadPool
} from
'poolifier'
2 import { type FastifyPluginCallback
} from
'fastify'
3 import fp from
'fastify-plugin'
5 type FastifyPoolifierOptions
,
10 const fastifyPoolifierPlugin
: FastifyPluginCallback
<FastifyPoolifierOptions
> = (
15 const pool
= new DynamicThreadPool
<WorkerData
, WorkerResponse
>(
21 if (!fastify
.hasDecorator('pool')) {
22 fastify
.decorate('pool', pool
)
24 if (!fastify
.hasDecorator('execute')) {
27 async (data
?: WorkerData
, name
?: string): Promise
<WorkerResponse
> =>
28 await pool
.execute(data
, name
)
34 export const fastifyPoolifier
= fp(fastifyPoolifierPlugin
, {
36 name
: 'fastify-poolifier'