docs: document availableParallelism() usage
[poolifier.git] / examples / fixedExample.js
index 478c37eb056229360dbdbabcf61ab13e7f058e74..2346f7b4f0b68b207ced0df9ffd86f125e36a1e5 100644 (file)
@@ -1,12 +1,17 @@
-const { FixedThreadPool, PoolEvents } = require('poolifier')
-let resolved = 0
-let poolBusy = 0
-const pool = new FixedThreadPool(15, './yourWorker.js', {
+const {
+  FixedThreadPool,
+  PoolEvents,
+  availableParallelism
+} = require('poolifier')
+
+const pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', {
   errorHandler: e => console.error(e),
   onlineHandler: () => console.info('worker is online')
 })
+let poolBusy = 0
 pool.emitter.on(PoolEvents.busy, () => poolBusy++)
 
+let resolved = 0
 const start = performance.now()
 const iterations = 1000
 for (let i = 1; i <= iterations; i++) {