repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build(deps-dev): apply updates
[poolifier.git]
/
examples
/
typescript
/
http-server-pool
/
fastify-cluster
/
src
/
worker.ts
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 8f4442ed748d3fd2abc62c108d361aa6f565d2e6..7003e265492b4e9d0c8d9974978e8c996bf7a0d6 100644
(file)
--- 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<WorkerData, WorkerResponse> {
private static fastify: FastifyInstance
class FastifyWorker extends ClusterWorker<WorkerData, WorkerResponse> {
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<WorkerResponse> => {
}
private static readonly startFastify = async (
workerData?: WorkerData
): Promise<WorkerResponse> => {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const { port } = workerData!
FastifyWorker.fastify = Fastify({
const { port } = workerData!
FastifyWorker.fastify = Fastify({
- logger: true
+ logger: true
,
})
FastifyWorker.fastify.all('/api/echo', request => {
})
FastifyWorker.fastify.all('/api/echo', request => {
@@
-32,13
+39,13
@@
class FastifyWorker extends ClusterWorker<WorkerData, WorkerResponse> {
Params: { number: number }
}>('/api/factorial/:number', request => {
const { number } = request.params
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,
})
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<WorkerData, WorkerResponse> {
super(FastifyWorker.startFastify, {
killHandler: async () => {
await FastifyWorker.fastify.close()
super(FastifyWorker.startFastify, {
killHandler: async () => {
await FastifyWorker.fastify.close()
- }
+ }
,
})
}
}
})
}
}