X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fhttp-server-pool%2Fexpress-hybrid%2Fsrc%2Fexpress-worker.ts;h=7ba9f374f5fa248012fab50afb72e508f8391de4;hb=c09a9dad768ec542a18baf46d2b9714f73da4aa6;hp=c7ca23adee4a4c2c48ec5a06f9792f93d45438fe;hpb=852b1334a4cf0b0446603a0f1d817c3f4afbfa07;p=poolifier.git diff --git a/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts b/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts index c7ca23ad..7ba9f374 100644 --- a/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts +++ b/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts @@ -1,11 +1,13 @@ import type { Server } from 'node:http' import type { AddressInfo } from 'node:net' + +import express, { type Express, type Request, type Response } from 'express' import { + availableParallelism, ClusterWorker, - DynamicThreadPool, - availableParallelism + DynamicThreadPool } from 'poolifier' -import express, { type Express, type Request, type Response } from 'express' + import { type ClusterWorkerData, type ClusterWorkerResponse, @@ -32,7 +34,7 @@ ClusterWorkerResponse workerData?: ClusterWorkerData ): ClusterWorkerResponse => { const { port, workerFile, minWorkers, maxWorkers, ...poolOptions } = - workerData as ClusterWorkerData + workerData! ExpressWorker.requestHandlerPool = new DynamicThreadPool< ThreadWorkerData, @@ -68,15 +70,16 @@ ClusterWorkerResponse .catch(emptyFunction) }) + let listenerPort: number | undefined ExpressWorker.server = application.listen(port, () => { + listenerPort = (ExpressWorker.server.address() as AddressInfo).port console.info( - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - `⚡️[express server]: Express server is started in cluster worker at http://localhost:${port}/` + `⚡️[express server]: Express server is started in cluster worker at http://localhost:${listenerPort}/` ) }) return { status: true, - port: (ExpressWorker.server.address() as AddressInfo)?.port ?? port + port: listenerPort ?? port } }