X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fwebsocket-server-pool%2Fws-worker_threads%2Fsrc%2Fmain.ts;h=7a162499d8f91417246fe1b94289b62083ec584d;hb=5a44cb5d4d40d5d78146d26b92c94825dd2e3797;hp=1eda1e92dd3b8f47ecbde99b9098768388eb92cf;hpb=d2bc8d8026164b1389822feced0f42af20552176;p=poolifier.git diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts b/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts index 1eda1e92..7a162499 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts @@ -1,16 +1,17 @@ import { type RawData, WebSocketServer } from 'ws' -import { type DataPayload, type MessagePayload, MessageType } from './types.js' + import { requestHandlerPool } from './pool.js' +import { type DataPayload, type MessagePayload, MessageType } from './types.js' const port = 8080 const wss = new WebSocketServer({ port }, () => { console.info( - `⚡️[ws server]: WebSocket server is started at http://localhost:${port}/` + `⚡️[ws server]: WebSocket server is started at ws://localhost:${port}/` ) }) const emptyFunction = (): void => { - /** Intentional */ + /* Intentional */ } wss.on('connection', ws => { @@ -31,7 +32,7 @@ wss.on('connection', ws => { data: response.data }) ) - return null + return undefined }) .catch(emptyFunction) break @@ -40,12 +41,15 @@ wss.on('connection', ws => { .execute({ data }, 'factorial') .then(response => { ws.send( - JSON.stringify({ - type: MessageType.factorial, - data: response.data - }) + JSON.stringify( + { + type: MessageType.factorial, + data: response.data + }, + (_, v) => (typeof v === 'bigint' ? v.toString() : v) + ) ) - return null + return undefined }) .catch(emptyFunction) break