X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fpool.ts;h=144d55002bd048ea865365cb6696cdb887745230;hb=d577f930d487c04ab3a6d63cbd25f68f95bc4298;hp=f85496434c2516eea46c7b5f1cde937565a2985d;hpb=6f65a0015850a7a5821cea00eb6d24cf046e5f19;p=poolifier.git diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index f8549643..144d5500 100644 --- a/examples/typescript/pool.ts +++ b/examples/typescript/pool.ts @@ -1,19 +1,18 @@ -import { dirname, extname, join } from 'path' -import { fileURLToPath } from 'url' -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' -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>( +export const fixedPool = new FixedThreadPool( availableParallelism(), workerFile, { @@ -26,7 +25,7 @@ export const fixedPool = new FixedThreadPool>( } ) -export const dynamicPool = new DynamicThreadPool>( +export const dynamicPool = new DynamicThreadPool( Math.floor(availableParallelism() / 2), availableParallelism(), workerFile, @@ -39,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)