X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fpool.ts;h=57898d98a9d53a8c89c3d774847e9cae694a53fe;hb=0e5402633adaf3af5ce1148c9d4364b54c69d64f;hp=b6bb4da3427a93132842e5953cd6fa858d52408d;hpb=f65efa796405c785a1ab5e646e30fc27418a6151;p=poolifier.git diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index b6bb4da3..57898d98 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 'node:path' +import { fileURLToPath } from 'node:url' +import type { MyData, MyResponse } from './worker.js' import { DynamicThreadPool, FixedThreadPool, 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, '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) @@ -32,3 +38,9 @@ export const dynamicPool = new DynamicThreadPool>( } } ) + +// eslint-disable-next-line @typescript-eslint/no-misused-promises +setTimeout(async () => { + await fixedPool.destroy() + await dynamicPool.destroy() +}, 3000)