import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import type { MyData, MyResponse } from './worker'
import {
+ availableParallelism,
DynamicThreadPool,
FixedThreadPool,
- availableParallelism
} from 'poolifier'
+import type { MyData, MyResponse } from './worker.js'
+
const workerFile = join(
dirname(fileURLToPath(import.meta.url)),
`worker${extname(fileURLToPath(import.meta.url))}`
)
-export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
+const fixedPool = new FixedThreadPool<MyData, MyResponse>(
availableParallelism(),
workerFile,
{
},
onlineHandler: () => {
console.info('Worker is online')
- }
+ },
}
)
-export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
+await fixedPool.execute()
+
+const dynamicPool = new DynamicThreadPool<MyData, MyResponse>(
Math.floor(availableParallelism() / 2),
availableParallelism(),
workerFile,
},
onlineHandler: () => {
console.info('Worker is online')
- }
+ },
}
)
+
+await dynamicPool.execute()
+
+// eslint-disable-next-line @typescript-eslint/no-misused-promises
+setTimeout(async () => {
+ await fixedPool.destroy()
+ await dynamicPool.destroy()
+}, 3000)