repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge dependabot/npm_and_yarn/examples/typescript/websocket-server-pool/ws-worker_thr...
[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 ee64ee2ec3911257f86e90a48702116676692afa..5fca89058695c7a45614b15d2eeb10bd690d9491 100644
(file)
--- a/
examples/typescript/http-server-pool/fastify-cluster/src/worker.ts
+++ b/
examples/typescript/http-server-pool/fastify-cluster/src/worker.ts
@@
-3,20
+3,20
@@
import { ClusterWorker } from 'poolifier'
import Fastify, { type FastifyInstance } from 'fastify'
import type { WorkerData, WorkerResponse } from './types.js'
import Fastify, { type FastifyInstance } from 'fastify'
import type { WorkerData, WorkerResponse } from './types.js'
-const factorial: (n: number) => number = n => {
- if (n === 0) {
- return 1
- }
- return factorial(n - 1) * n
-}
-
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
+ }
+ return FastifyWorker.factorial(n - 1) * n
+ }
+
private static readonly startFastify = async (
workerData?: WorkerData
): Promise<WorkerResponse> => {
private static readonly startFastify = async (
workerData?: WorkerData
): Promise<WorkerResponse> => {
- const { port } = workerData
as WorkerData
+ const { port } = workerData
!
FastifyWorker.fastify = Fastify({
logger: true
FastifyWorker.fastify = Fastify({
logger: true
@@
-30,13
+30,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: factorial(number) }
+ return { number:
FastifyWorker.
factorial(number) }
})
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
}
}
}
}