From 9bc1ca7575fb508018f641dfee8c9939beda517a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 10 Aug 2023 02:32:19 +0200 Subject: [PATCH] refactor: make TS code example also works with TS interpreter like ts-node MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- examples/typescript/pool.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index a53857c0..93774422 100644 --- a/examples/typescript/pool.ts +++ b/examples/typescript/pool.ts @@ -1,4 +1,4 @@ -import { dirname, join } from 'path' +import { dirname, extname, join } from 'path' import { fileURLToPath } from 'url' import type { MyData, MyResponse } from './worker' import { @@ -7,9 +7,14 @@ import { availableParallelism } from 'poolifier' +const workerFile = join( + dirname(fileURLToPath(import.meta.url)), + `worker${extname(fileURLToPath(import.meta.url))}` +) + export const fixedPool = new FixedThreadPool>( availableParallelism(), - join(dirname(fileURLToPath(import.meta.url)), 'worker.js'), + workerFile, { errorHandler: (e: Error) => { console.error(e) @@ -23,7 +28,7 @@ export const fixedPool = new FixedThreadPool>( export const dynamicPool = new DynamicThreadPool>( Math.floor(availableParallelism() / 2), availableParallelism(), - join(dirname(fileURLToPath(import.meta.url)), 'worker.js'), + workerFile, { errorHandler: (e: Error) => { console.error(e) -- 2.34.1