X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fpool.ts;h=ab6d4f268b38a76520cf15b919948eae3e9eb924;hb=312d0c0d244192a22032d2ec20fee705725f9f14;hp=b6bb4da3427a93132842e5953cd6fa858d52408d;hpb=f65efa796405c785a1ab5e646e30fc27418a6151;p=poolifier.git diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index b6bb4da3..ab6d4f26 100644 --- a/examples/typescript/pool.ts +++ b/examples/typescript/pool.ts @@ -1,14 +1,20 @@ -import { join } from 'path' -import type { MyData, MyResponse } from './worker' +import { dirname, extname, join } from 'path' +import { fileURLToPath } from 'url' import { DynamicThreadPool, FixedThreadPool, availableParallelism } from 'poolifier' +import type { MyData, MyResponse } from './worker' + +const workerFile = join( + dirname(fileURLToPath(import.meta.url)), + `worker${extname(fileURLToPath(import.meta.url))}` +) export const fixedPool = new FixedThreadPool>( availableParallelism(), - join(__dirname, 'worker.js'), + workerFile, { errorHandler: (e: Error) => { console.error(e) @@ -20,9 +26,9 @@ export const fixedPool = new FixedThreadPool>( ) export const dynamicPool = new DynamicThreadPool>( - availableParallelism() / 2, + Math.floor(availableParallelism() / 2), availableParallelism(), - join(__dirname, 'worker.js'), + workerFile, { errorHandler: (e: Error) => { console.error(e)