From b2b02b3dade2a6fe409865e05c11ed20e466c920 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 10 Aug 2023 22:07:05 +0200 Subject: [PATCH] docs: add links to examples MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 6 +++++- examples/typescript/http-client/package.json | 4 ++-- examples/typescript/http-client/src/main.ts | 10 +++++----- examples/typescript/http-client/src/pool.ts | 5 ++++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 151c658e..77de1272 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,11 @@ pool 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. diff --git a/examples/typescript/http-client/package.json b/examples/typescript/http-client/package.json index 27530880..9d09531a 100644 --- a/examples/typescript/http-client/package.json +++ b/examples/typescript/http-client/package.json @@ -1,8 +1,8 @@ { "$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": { diff --git a/examples/typescript/http-client/src/main.ts b/examples/typescript/http-client/src/main.ts index 067aa2d2..1f4532c9 100644 --- a/examples/typescript/http-client/src/main.ts +++ b/examples/typescript/http-client/src/main.ts @@ -1,20 +1,20 @@ 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>() + const httpClientPoolPromises = new Set>() 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 ${ diff --git a/examples/typescript/http-client/src/pool.ts b/examples/typescript/http-client/src/pool.ts index 77ceacba..139f3fb9 100644 --- a/examples/typescript/http-client/src/pool.ts +++ b/examples/typescript/http-client/src/pool.ts @@ -8,11 +8,14 @@ const workerFile = join( `worker${extname(fileURLToPath(import.meta.url))}` ) -export const fetchPool = new FixedThreadPool( +export const httpClientPool = new FixedThreadPool( availableParallelism(), workerFile, { enableTasksQueue: true, + tasksQueueOptions: { + concurrency: 8 + }, errorHandler: (e: Error) => { console.error(e) } -- 2.34.1