From 6ff35e73fc136a503f3ca344b36049361903b9cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 11 Aug 2023 21:17:35 +0200 Subject: [PATCH] refactor: add default options values to fastify example MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../fastify/src/fastify-poolifier.ts | 13 ++++++++++--- .../http-server-pool/fastify/src/types.ts | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) 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 } -- 2.34.1