X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fpool.ts;h=de49c93ad6f8c73bc3cfaa680a78134cdd8daa56;hb=4511441a7858ae4871037148b3c9505ac422f4f2;hp=a53857c0f311a63ff321b4ce08b9e1ef02465dcd;hpb=1adc6af72c087b9412e625bc9576be67d40e7397;p=poolifier.git diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index a53857c0..de49c93a 100644 --- a/examples/typescript/pool.ts +++ b/examples/typescript/pool.ts @@ -1,5 +1,5 @@ -import { dirname, join } from 'path' -import { fileURLToPath } from 'url' +import { dirname, extname, join } from 'node:path' +import { fileURLToPath } from 'node:url' import type { MyData, MyResponse } from './worker' import { DynamicThreadPool, @@ -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) @@ -33,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)