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-cluster...
[poolifier.git]
/
examples
/
typescript
/
websocket-server-pool
/
ws-hybrid
/
src
/
websocket-server-worker.ts
diff --git
a/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts
b/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts
index bd7b8fbbdaba6ed616069b663e3bb2bc1507753d..ec6a3d18736f119cb27f5e32988fe464f5d2d3d4 100644
(file)
--- a/
examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts
+++ b/
examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts
@@
-15,7
+15,7
@@
import {
} from './types.js'
const emptyFunction = (): void => {
} from './types.js'
const emptyFunction = (): void => {
- /*
*
Intentional */
+ /* Intentional */
}
class WebSocketServerWorker extends ClusterWorker<
}
class WebSocketServerWorker extends ClusterWorker<
@@
-31,22
+31,25
@@
ClusterWorkerResponse
private static readonly startWebSocketServer = (
workerData?: ClusterWorkerData
): ClusterWorkerResponse => {
private static readonly startWebSocketServer = (
workerData?: ClusterWorkerData
): ClusterWorkerResponse => {
- const { port } = workerData as ClusterWorkerData
- WebSocketServerWorker.wss = new WebSocketServer({ port }, () => {
- console.info(
- `⚡️[ws server]: WebSocket server is started in cluster worker at ws://localhost:${port}/`
- )
- })
+ const { port, workerFile, minWorkers, maxWorkers, ...poolOptions } =
+ workerData as ClusterWorkerData
WebSocketServerWorker.requestHandlerPool = new DynamicThreadPool<
ThreadWorkerData<DataPayload>,
ThreadWorkerResponse<DataPayload>
>(
WebSocketServerWorker.requestHandlerPool = new DynamicThreadPool<
ThreadWorkerData<DataPayload>,
ThreadWorkerResponse<DataPayload>
>(
- workerData?.minWorkers ?? 1,
- workerData?.maxWorkers ?? availableParallelism(),
- workerData?.workerFile as string
+ minWorkers ?? 1,
+ maxWorkers ?? availableParallelism(),
+ workerFile,
+ poolOptions
)
)
+ 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 => {
ws.on('error', console.error)
ws.on('message', (message: RawData) => {
WebSocketServerWorker.wss.on('connection', ws => {
ws.on('error', console.error)
ws.on('message', (message: RawData) => {
@@
-93,7
+96,12
@@
ClusterWorkerResponse
}
public constructor () {
}
public constructor () {
- super(WebSocketServerWorker.startWebSocketServer)
+ super(WebSocketServerWorker.startWebSocketServer, {
+ killHandler: async () => {
+ await WebSocketServerWorker.requestHandlerPool.destroy()
+ WebSocketServerWorker.wss.close()
+ }
+ })
}
}
}
}