docs: refine CHANGELOG.md
[poolifier.git] / examples / typescript / pool.ts
index c2d0a1b8d1f1ba004993d820f8dcdef28f3bd7aa..54b437ab31b2f1d7785439c5ce9007167e554331 100644 (file)
@@ -1,30 +1,34 @@
 import { join } from 'path'
-import { DynamicThreadPool, FixedThreadPool } from 'poolifier'
 import type { MyData, MyResponse } from './worker'
+import {
+  DynamicThreadPool,
+  FixedThreadPool,
+  availableParallelism
+} from 'poolifier'
 
 export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
-  8,
+  availableParallelism(),
   join(__dirname, 'worker.js'),
   {
     errorHandler: (e: Error) => {
       console.error(e)
     },
     onlineHandler: () => {
-      console.log('Worker is online')
+      console.info('Worker is online')
     }
   }
 )
 
 export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
-  2,
-  8,
+  Math.floor(availableParallelism() / 2),
+  availableParallelism(),
   join(__dirname, 'worker.js'),
   {
     errorHandler: (e: Error) => {
       console.error(e)
     },
     onlineHandler: () => {
-      console.log('Worker is online')
+      console.info('Worker is online')
     }
   }
 )