From: Jérôme Benoit Date: Wed, 27 Mar 2024 17:12:19 +0000 (+0100) Subject: docs: refactor TS example X-Git-Tag: v3.1.28~24 X-Git-Url: https://git.piment-noir.org/?p=poolifier.git;a=commitdiff_plain;h=fbcf5e158672b78b5c495f30df86699a1b2360d4 docs: refactor TS example Signed-off-by: Jérôme Benoit --- diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index c55c4e96..fb48f7b0 100644 --- a/examples/typescript/pool.ts +++ b/examples/typescript/pool.ts @@ -14,7 +14,7 @@ const workerFile = join( `worker${extname(fileURLToPath(import.meta.url))}` ) -export const fixedPool = new FixedThreadPool( +const fixedPool = new FixedThreadPool( availableParallelism(), workerFile, { @@ -27,7 +27,9 @@ export const fixedPool = new FixedThreadPool( } ) -export const dynamicPool = new DynamicThreadPool( +await fixedPool.execute() + +const dynamicPool = new DynamicThreadPool( Math.floor(availableParallelism() / 2), availableParallelism(), workerFile, @@ -41,6 +43,8 @@ export const dynamicPool = new DynamicThreadPool( } ) +await dynamicPool.execute() + // eslint-disable-next-line @typescript-eslint/no-misused-promises setTimeout(async () => { await fixedPool.destroy() diff --git a/examples/typescript/worker.ts b/examples/typescript/worker.ts index 79819d98..1d8af8d9 100644 --- a/examples/typescript/worker.ts +++ b/examples/typescript/worker.ts @@ -20,7 +20,7 @@ class MyThreadWorker extends ThreadWorker { return await new Promise(resolve => { setTimeout(() => { resolve({ message: 'Hello from Worker :)', data }) - }, 10000) + }, 1000) }) } }