Merge pull request #1232 from poolifier/combined-prs-branch
[poolifier.git] / benchmarks / versus-external-pools / dynamic-node-worker-threads-pool.mjs
index 743b01d64e2b6086af087311809825d56c533f6d..c4be1ee1c6d1a0ca312d1597c1d8e4a48406d5fd 100644 (file)
@@ -1,9 +1,7 @@
-// IMPORT LIBRARIES
 import { DynamicPool } from 'node-worker-threads-pool'
-// FINISH IMPORT LIBRARIES
-// IMPORT FUNCTION TO BENCH
-import functionToBench from './functions/function-to-bench.mjs'
-// FINISH IMPORT FUNCTION TO BENCH
+import { executeAsyncFn } from './utils.mjs'
+import functionToBench from './functions/function-to-bench.js'
+
 const size = parseInt(process.env.POOL_SIZE)
 const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
@@ -12,15 +10,16 @@ const data = {
   taskSize: parseInt(process.env.TASK_SIZE)
 }
 
-const pool = new DynamicPool(size)
+const dynamicPool = new DynamicPool(size)
 
 async function run () {
-  const promises = []
+  const promises = new Set()
   for (let i = 0; i < iterations; i++) {
-    promises.push(
-      pool.exec({
+    promises.add(
+      dynamicPool.exec({
         task: functionToBench,
-        param: data
+        param: data,
+        timeout: 60000 // this is the same as poolifier default
       })
     )
   }
@@ -29,4 +28,4 @@ async function run () {
   process.exit()
 }
 
-await run()
+await executeAsyncFn(run)