build(deps-dev): apply updates
[poolifier.git] / examples / typescript / websocket-server-pool / ws-hybrid / src / main.ts
index d9e827cbfa262f83613cb01c8201b70efdfec4a7..f1c755060a118c6177c9f2d814578b305e3c0faa 100644 (file)
@@ -1,7 +1,9 @@
 import { dirname, extname, join } from 'node:path'
 import { fileURLToPath } from 'node:url'
-import { FixedClusterPool, availableParallelism } from 'poolifier'
-import { type ClusterWorkerData, type ClusterWorkerResponse } from './types.js'
+
+import { availableParallelism, FixedClusterPool } from 'poolifier'
+
+import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js'
 
 const webSocketServerWorkerFile = join(
   dirname(fileURLToPath(import.meta.url)),
@@ -17,11 +19,15 @@ const pool = new FixedClusterPool<ClusterWorkerData, ClusterWorkerResponse>(
   Math.round(availableParallelism() / 2),
   webSocketServerWorkerFile,
   {
+    enableEvents: false,
     onlineHandler: () => {
       pool
         .execute({
           port: 8080,
-          maxWorkers: Math.round(availableParallelism() / 2),
+          maxWorkers:
+            Math.round(availableParallelism() / 4) < 1
+              ? 1
+              : Math.round(availableParallelism() / 4),
           workerFile: requestHandlerWorkerFile,
           enableTasksQueue: true,
           tasksQueueOptions: {
@@ -34,13 +40,12 @@ const pool = new FixedClusterPool<ClusterWorkerData, ClusterWorkerResponse>(
         .then(response => {
           if (response.status) {
             console.info(
-              // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
               `WebSocket server is listening in cluster worker on port ${response.port}`
             )
           }
-          return null
+          return undefined
         })
-        .catch(error => {
+        .catch((error: unknown) => {
           console.error(
             'WebSocket server failed to start in cluster worker:',
             error