refactor: cleanup object destructuration in examples
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 16 Aug 2023 14:04:38 +0000 (16:04 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 16 Aug 2023 14:04:38 +0000 (16:04 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts
examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts
examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts

index a8ffbcb28fe0a5e6205b48964596d79d9520be41..56fad6d1b9edec47d79dd4e283dfe638e9507dfd 100644 (file)
@@ -31,7 +31,7 @@ ClusterWorkerResponse
   private static readonly startExpress = (
     workerData?: ClusterWorkerData
   ): ClusterWorkerResponse => {
-    const { port, workerFile, minWorkers, maxWorkers } =
+    const { port, workerFile, minWorkers, maxWorkers, ...poolOptions } =
       workerData as ClusterWorkerData
 
     ExpressWorker.requestHandlerPool = new DynamicThreadPool<
@@ -41,7 +41,7 @@ ClusterWorkerResponse
       minWorkers ?? 1,
       maxWorkers ?? availableParallelism(),
       workerFile,
-      workerData
+      poolOptions
     )
 
     const application: Express = express()
index 9c2cb3c52d57e95f5452e624a0bde9ffd4e1a4ed..e21eb58c01294014fd9557f067c6544bcfcca18a 100644 (file)
@@ -13,13 +13,16 @@ ClusterWorkerResponse
   private static readonly startFastify = async (
     workerData?: ClusterWorkerData
   ): Promise<ClusterWorkerResponse> => {
-    const { port } = workerData as ClusterWorkerData
+    const { port, ...fastifyPoolifierOptions } = workerData as ClusterWorkerData
 
     FastifyWorker.fastify = Fastify({
       logger: true
     })
 
-    await FastifyWorker.fastify.register(fastifyPoolifier, workerData)
+    await FastifyWorker.fastify.register(
+      fastifyPoolifier,
+      fastifyPoolifierOptions
+    )
 
     FastifyWorker.fastify.all('/api/echo', async (request) => {
       return (
index 7b4aa070f591a7240d6be5e6f9c5e842398e0d0c..437fae1b45600c5cb0bc700d690569c820b44b5e 100644 (file)
@@ -31,7 +31,7 @@ ClusterWorkerResponse
   private static readonly startWebSocketServer = (
     workerData?: ClusterWorkerData
   ): ClusterWorkerResponse => {
-    const { port, workerFile, minWorkers, maxWorkers } =
+    const { port, workerFile, minWorkers, maxWorkers, ...poolOptions } =
       workerData as ClusterWorkerData
 
     WebSocketServerWorker.requestHandlerPool = new DynamicThreadPool<
@@ -41,7 +41,7 @@ ClusterWorkerResponse
       minWorkers ?? 1,
       maxWorkers ?? availableParallelism(),
       workerFile,
-      workerData
+      poolOptions
     )
 
     WebSocketServerWorker.wss = new WebSocketServer({ port }, () => {