067aa2d23668d8068efa55dbce1fdf570743193a
1 import { availableParallelism
} from
'poolifier'
2 import { fetchPool
} from
'./pool.js'
3 import { type WorkerResponse
} from
'./types.js'
5 const parallelism
= availableParallelism()
6 const requestUrl
= 'http://localhost:8080/'
8 for (const workerFunction
of ['node_fetch', 'fetch', 'axios']) {
9 const fetchPoolPromises
= new Set
<Promise
<WorkerResponse
>>()
10 for (let i
= 0; i
< availableParallelism(); i
++) {
11 fetchPoolPromises
.add(
12 fetchPool
.execute({ input
: requestUrl
}, workerFunction
)
16 const now
= performance
.now()
17 const responses
= await Promise
.all(fetchPoolPromises
)
18 const elapsedTime
= performance
.now() - now
20 `Received in ${elapsedTime.toFixed(2)}ms an array with ${
22 } responses from ${parallelism} parallel requests made with ${workerFunction} on ${requestUrl}:\n`,