1 const FixedThreadPool
= require('../lib/fixed')
2 const DynamicThreadPool
= require('../lib/dynamic')
3 const Pool
= require('worker-threads-pool')
8 const externalPool
= new Pool({ max
: size
})
9 const fixedPool
= new FixedThreadPool(size
, './yourWorker.js', {
12 const dynamicPool
= new DynamicThreadPool(
20 const workerData
= { proof
: 'ok' }
23 async
function fixedTest () {
25 const time
= Date
.now()
26 for (let i
= 0; i
<= tasks
; i
++) {
27 fixedPool
.execute(workerData
).then(res
=> {
29 if (executions
=== tasks
) {
31 `Fixed pool take ${Date.now() - time} to work on ${executions} tasks`
38 async
function dynamicTest () {
40 const time
= Date
.now()
41 for (let i
= 0; i
<= tasks
; i
++) {
42 dynamicPool
.execute(workerData
).then(res
=> {
44 if (executions
=== tasks
) {
48 } to work on ${executions} tasks`
55 async
function externalPoolTest () {
57 const time
= Date
.now()
58 for (let i
= 0; i
<= tasks
; i
++) {
59 new Promise((resolve
, reject
) => {
61 './externalWorker.js',
62 { workerData
: workerData
},
67 worker
.on('error', reject
)
68 worker
.on('message', res
=> {
75 if (tasks
=== executions
) {
77 `External pool take ${
79 } to work on ${executions} tasks`
86 async
function test () {