From: Jérôme Benoit Date: Thu, 10 Aug 2023 00:32:19 +0000 (+0200) Subject: refactor: make TS code example also works with TS interpreter like X-Git-Tag: v2.6.23~23 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9bc1ca7575fb508018f641dfee8c9939beda517a;p=poolifier.git refactor: make TS code example also works with TS interpreter like ts-node Signed-off-by: Jérôme Benoit --- 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)