docs: refine benchmark README.md
[poolifier.git] / benchmarks / versus-external-pools / dynamic-node-worker-threads-pool.mjs
index 204049749d2e171a1cb067ec550179cf65a124fa..08535b68e1eabc78d6c9fc2437c1244324a697e3 100644 (file)
@@ -1,9 +1,7 @@
-// IMPORT LIBRARIES
 import { DynamicPool } from 'node-worker-threads-pool'
-// FINISH IMPORT LIBRARIES
-// IMPORT FUNCTION TO BENCH
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
 import functionToBench from './functions/function-to-bench.js'
-// FINISH IMPORT FUNCTION TO BENCH
+
 const size = parseInt(process.env.POOL_SIZE)
 const iterations = parseInt(process.env.NUM_ITERATIONS)
 const data = {
@@ -12,13 +10,13 @@ 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,
         timeout: 60000 // this is the same as poolifier default
@@ -30,4 +28,4 @@ async function run () {
   process.exit()
 }
 
-await run()
+await executeAsyncFn(run)