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): bump rollup
[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 efe0facdc900b96ae4b4d49d36da3729a598147a..5e758eb7d3f845e1d8508bf907bda9fa7fcbcc3d 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,7
+8,7
@@
import {
type WorkerResponse
} from './types.js'
type WorkerResponse
} from './types.js'
-const factorial: (n: number) => number =
(n)
=> {
+const factorial: (n: number) => number =
n
=> {
if (n === 0) {
return 1
}
if (n === 0) {
return 1
}
@@
-22,13
+22,14
@@
class WebSocketServerWorker extends ClusterWorker<WorkerData, WorkerResponse> {
workerData?: WorkerData
): WorkerResponse => {
const { port } = workerData as WorkerData
workerData?: WorkerData
): WorkerResponse => {
const { port } = workerData as WorkerData
+
WebSocketServerWorker.wss = new WebSocketServer({ port }, () => {
console.info(
`⚡️[ws server]: WebSocket server is started in cluster worker at ws://localhost:${port}/`
)
})
WebSocketServerWorker.wss = new WebSocketServer({ port }, () => {
console.info(
`⚡️[ws server]: WebSocket server is started in cluster worker at ws://localhost:${port}/`
)
})
- 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(
@@
-62,7
+63,11
@@
class WebSocketServerWorker extends ClusterWorker<WorkerData, WorkerResponse> {
}
public constructor () {
}
public constructor () {
- super(WebSocketServerWorker.startWebSocketServer)
+ super(WebSocketServerWorker.startWebSocketServer, {
+ killHandler: () => {
+ WebSocketServerWorker.wss.close()
+ }
+ })
}
}
}
}