docs: refactor TS example
[poolifier.git] / examples / typescript / pool.ts
index c55c4e96557dc8fcb400847745b0ac2c5ee014c7..fb48f7b07db76324a75afc001e131dd448a6809f 100644 (file)
@@ -14,7 +14,7 @@ const workerFile = join(
   `worker${extname(fileURLToPath(import.meta.url))}`
 )
 
-export const fixedPool = new FixedThreadPool<MyData, MyResponse>(
+const fixedPool = new FixedThreadPool<MyData, MyResponse>(
   availableParallelism(),
   workerFile,
   {
@@ -27,7 +27,9 @@ export const fixedPool = new FixedThreadPool<MyData, MyResponse>(
   }
 )
 
-export const dynamicPool = new DynamicThreadPool<MyData, MyResponse>(
+await fixedPool.execute()
+
+const dynamicPool = new DynamicThreadPool<MyData, MyResponse>(
   Math.floor(availableParallelism() / 2),
   availableParallelism(),
   workerFile,
@@ -41,6 +43,8 @@ export const dynamicPool = new DynamicThreadPool<MyData, MyResponse>(
   }
 )
 
+await dynamicPool.execute()
+
 // eslint-disable-next-line @typescript-eslint/no-misused-promises
 setTimeout(async () => {
   await fixedPool.destroy()