You can do the same with the classes _ClusterWorker_, _FixedClusterPool_ and _DynamicClusterPool_.
-**See [examples](./examples/) folder for more details (in particular if you want to use a pool with [multiple task functions](./examples/multiFunctionExample.js))**.
+**See [examples](./examples/) folder for more details**:
+
+- [Javascript](./examples/)
+- [Typescript](./examples/typescript/)
+ - [HTTP client pool](./examples/typescript/http-client/)
Remember that workers can only send and receive structured-cloneable data.
{
"$schema": "https://json.schemastore.org/package",
- "name": "http-client-node-fetch",
+ "name": "http-client-pool",
"version": "1.0.0",
- "description": "multithreaded node-fetch",
+ "description": "HTTP client pool",
"main": "dist/main.js",
"type": "module",
"volta": {
import { availableParallelism } from 'poolifier'
-import { fetchPool } from './pool.js'
+import { httpClientPool } from './pool.js'
import { type WorkerResponse } from './types.js'
const parallelism = availableParallelism()
const requestUrl = 'http://localhost:8080/'
for (const workerFunction of ['node_fetch', 'fetch', 'axios']) {
- const fetchPoolPromises = new Set<Promise<WorkerResponse>>()
+ const httpClientPoolPromises = new Set<Promise<WorkerResponse>>()
for (let i = 0; i < availableParallelism(); i++) {
- fetchPoolPromises.add(
- fetchPool.execute({ input: requestUrl }, workerFunction)
+ httpClientPoolPromises.add(
+ httpClientPool.execute({ input: requestUrl }, workerFunction)
)
}
try {
const now = performance.now()
- const responses = await Promise.all(fetchPoolPromises)
+ const responses = await Promise.all(httpClientPoolPromises)
const elapsedTime = performance.now() - now
console.info(
`Received in ${elapsedTime.toFixed(2)}ms an array with ${
`worker${extname(fileURLToPath(import.meta.url))}`
)
-export const fetchPool = new FixedThreadPool<WorkerData, WorkerResponse>(
+export const httpClientPool = new FixedThreadPool<WorkerData, WorkerResponse>(
availableParallelism(),
workerFile,
{
enableTasksQueue: true,
+ tasksQueueOptions: {
+ concurrency: 8
+ },
errorHandler: (e: Error) => {
console.error(e)
}