X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fhttp-server-pool%2Ffastify-cluster%2Fsrc%2Fworker.ts;h=7003e265492b4e9d0c8d9974978e8c996bf7a0d6;hb=17dd78334af5f98262f85c011f7cf667d7306559;hp=8f4442ed748d3fd2abc62c108d361aa6f565d2e6;hpb=ea4b5fd037c5fe09eb6a2810332ad6bed1b5bc7f;p=poolifier.git diff --git a/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts b/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts index 8f4442ed..7003e265 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts +++ b/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts @@ -8,20 +8,27 @@ import type { WorkerData, WorkerResponse } from './types.js' class FastifyWorker extends ClusterWorker { private static fastify: FastifyInstance - private static readonly factorial = (n: number): number => { - if (n === 0) { - return 1 + private static readonly factorial = (n: number | bigint): bigint => { + if (n === 0 || n === 1) { + return 1n + } else { + n = BigInt(n) + let factorial = 1n + for (let i = 1n; i <= n; i++) { + factorial *= i + } + return factorial } - return FastifyWorker.factorial(n - 1) * n } private static readonly startFastify = async ( workerData?: WorkerData ): Promise => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const { port } = workerData! FastifyWorker.fastify = Fastify({ - logger: true + logger: true, }) FastifyWorker.fastify.all('/api/echo', request => { @@ -32,13 +39,13 @@ class FastifyWorker extends ClusterWorker { Params: { number: number } }>('/api/factorial/:number', request => { const { number } = request.params - return { number: FastifyWorker.factorial(number) } + return { number: FastifyWorker.factorial(number).toString() } }) await FastifyWorker.fastify.listen({ port }) return { status: true, - port: (FastifyWorker.fastify.server.address() as AddressInfo).port + port: (FastifyWorker.fastify.server.address() as AddressInfo).port, } } @@ -46,7 +53,7 @@ class FastifyWorker extends ClusterWorker { super(FastifyWorker.startFastify, { killHandler: async () => { await FastifyWorker.fastify.close() - } + }, }) } }