From: Jérôme Benoit Date: Fri, 11 Aug 2023 19:17:35 +0000 (+0200) Subject: refactor: add default options values to fastify example X-Git-Tag: v2.6.23~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=6ff35e73fc136a503f3ca344b36049361903b9cc;p=poolifier.git refactor: add default options values to fastify example Signed-off-by: Jérôme Benoit --- diff --git a/examples/typescript/http-server-pool/fastify/src/fastify-poolifier.ts b/examples/typescript/http-server-pool/fastify/src/fastify-poolifier.ts index 36c1ea62..8419e781 100644 --- a/examples/typescript/http-server-pool/fastify/src/fastify-poolifier.ts +++ b/examples/typescript/http-server-pool/fastify/src/fastify-poolifier.ts @@ -1,4 +1,4 @@ -import { DynamicThreadPool } from 'poolifier' +import { DynamicThreadPool, availableParallelism } from 'poolifier' import { type FastifyPluginCallback } from 'fastify' import fp from 'fastify-plugin' import { @@ -12,9 +12,16 @@ const fastifyPoolifierPlugin: FastifyPluginCallback = ( options, done ) => { + options = { + ...{ + minWorkers: 1, + maxWorkers: availableParallelism() + }, + ...options + } const pool = new DynamicThreadPool( - options.minWorkers, - options.maxWorkers, + options.minWorkers as number, + options.maxWorkers as number, options.workerFile, options ) diff --git a/examples/typescript/http-server-pool/fastify/src/types.ts b/examples/typescript/http-server-pool/fastify/src/types.ts index 5c53f106..0bc9a017 100644 --- a/examples/typescript/http-server-pool/fastify/src/types.ts +++ b/examples/typescript/http-server-pool/fastify/src/types.ts @@ -14,6 +14,6 @@ export interface WorkerResponse { export interface FastifyPoolifierOptions extends ThreadPoolOptions { workerFile: string - maxWorkers: number - minWorkers: number + maxWorkers?: number + minWorkers?: number }