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
/
websocket-server-pool
/
ws-cluster
/
src
/
worker.ts
diff --git
a/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts
b/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts
index 143dc6db38deac7f40f27001b3aa51e7ba9c2e2b..0e8dc20a95fd8d2f3f161381d07f90a36e60b933 100644
(file)
--- a/
examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts
+++ b/
examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts
@@
-8,16
+8,16
@@
import {
type WorkerResponse
} from './types.js'
type WorkerResponse
} from './types.js'
-const factorial: (n: number) => number = (n) => {
- if (n === 0) {
- return 1
- }
- return factorial(n - 1) * n
-}
-
class WebSocketServerWorker extends ClusterWorker<WorkerData, WorkerResponse> {
private static wss: WebSocketServer
class WebSocketServerWorker extends ClusterWorker<WorkerData, WorkerResponse> {
private static wss: WebSocketServer
+ private static readonly factorial = (n: number): number => {
+ if (n === 0) {
+ return 1
+ }
+ return WebSocketServerWorker.factorial(n - 1) * n
+ }
+
private static readonly startWebSocketServer = (
workerData?: WorkerData
): WorkerResponse => {
private static readonly startWebSocketServer = (
workerData?: WorkerData
): WorkerResponse => {
@@
-29,7
+29,7
@@
class WebSocketServerWorker extends ClusterWorker<WorkerData, WorkerResponse> {
)
})
)
})
- WebSocketServerWorker.wss.on('connection',
(ws)
=> {
+ WebSocketServerWorker.wss.on('connection',
ws
=> {
ws.on('error', console.error)
ws.on('message', (message: RawData) => {
const { type, data } = JSON.parse(
ws.on('error', console.error)
ws.on('message', (message: RawData) => {
const { type, data } = JSON.parse(
@@
-49,7
+49,9
@@
class WebSocketServerWorker extends ClusterWorker<WorkerData, WorkerResponse> {
ws.send(
JSON.stringify({
type: MessageType.factorial,
ws.send(
JSON.stringify({
type: MessageType.factorial,
- data: { number: factorial(data.number as number) }
+ data: {
+ number: WebSocketServerWorker.factorial(data.number as number)
+ }
})
)
break
})
)
break