repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into combined-prs-branch
[poolifier.git]
/
examples
/
typescript
/
websocket-server-pool
/
ws-worker_threads
/
src
/
main.ts
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 9edb16b03a399768725b2b904f8186183136574e..7a162499d8f91417246fe1b94289b62083ec584d 100644
(file)
--- 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,6
+1,7
@@
import { type RawData, WebSocketServer } from 'ws'
import { type RawData, WebSocketServer } from 'ws'
-import { type DataPayload, type MessagePayload, MessageType } from './types.js'
+
import { requestHandlerPool } from './pool.js'
import { requestHandlerPool } from './pool.js'
+import { type DataPayload, type MessagePayload, MessageType } from './types.js'
const port = 8080
const wss = new WebSocketServer({ port }, () => {
const port = 8080
const wss = new WebSocketServer({ port }, () => {
@@
-10,10
+11,10
@@
const wss = new WebSocketServer({ port }, () => {
})
const emptyFunction = (): void => {
})
const emptyFunction = (): void => {
- /*
*
Intentional */
+ /* Intentional */
}
}
-wss.on('connection',
(ws)
=> {
+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(
@@
-24,28
+25,31
@@
wss.on('connection', (ws) => {
case MessageType.echo:
requestHandlerPool
.execute({ data }, 'echo')
case MessageType.echo:
requestHandlerPool
.execute({ data }, 'echo')
- .then(
(response)
=> {
+ .then(
response
=> {
ws.send(
JSON.stringify({
type: MessageType.echo,
data: response.data
})
)
ws.send(
JSON.stringify({
type: MessageType.echo,
data: response.data
})
)
- return
null
+ return
undefined
})
.catch(emptyFunction)
break
case MessageType.factorial:
requestHandlerPool
.execute({ data }, 'factorial')
})
.catch(emptyFunction)
break
case MessageType.factorial:
requestHandlerPool
.execute({ data }, 'factorial')
- .then(
(response)
=> {
+ .then(
response
=> {
ws.send(
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
})
.catch(emptyFunction)
break