build(deps-dev): apply updates
[poolifier.git] / examples / typescript / websocket-server-pool / ws-hybrid / src / main.ts
index b9e48bdd2ee194abf47d6d1b69eddd3dc134100d..0c31721a417c575c65342c41cfad5ef837e8103c 100644 (file)
@@ -1,7 +1,7 @@
 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 type { ClusterWorkerData, ClusterWorkerResponse } from './types.js'
 
 const webSocketServerWorkerFile = join(
   dirname(fileURLToPath(import.meta.url)),
@@ -21,7 +21,10 @@ const pool = new FixedClusterPool<ClusterWorkerData, ClusterWorkerResponse>(
       pool
         .execute({
           port: 8080,
-          maxWorkers: Math.round(availableParallelism() / 4),
+          maxWorkers:
+            Math.round(availableParallelism() / 4) < 1
+              ? 1
+              : Math.round(availableParallelism() / 4),
           workerFile: requestHandlerWorkerFile,
           enableTasksQueue: true,
           tasksQueueOptions: {
@@ -31,16 +34,16 @@ const pool = new FixedClusterPool<ClusterWorkerData, ClusterWorkerResponse>(
             console.error('Thread worker error:', e)
           }
         })
-        .then((response) => {
+        .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 => {
           console.error(
             'WebSocket server failed to start in cluster worker:',
             error