c55c4e96557dc8fcb400847745b0ac2c5ee014c7
1 import { dirname
, extname
, join
} from
'node:path'
2 import { fileURLToPath
} from
'node:url'
10 import type { MyData
, MyResponse
} from
'./worker.js'
12 const workerFile
= join(
13 dirname(fileURLToPath(import.meta
.url
)),
14 `worker${extname(fileURLToPath(import.meta.url))}`
17 export const fixedPool
= new FixedThreadPool
<MyData
, MyResponse
>(
18 availableParallelism(),
21 errorHandler
: (e
: Error) => {
24 onlineHandler
: () => {
25 console
.info('Worker is online')
30 export const dynamicPool
= new DynamicThreadPool
<MyData
, MyResponse
>(
31 Math.floor(availableParallelism() / 2),
32 availableParallelism(),
35 errorHandler
: (e
: Error) => {
38 onlineHandler
: () => {
39 console
.info('Worker is online')
44 // eslint-disable-next-line @typescript-eslint/no-misused-promises
45 setTimeout(async () => {
46 await fixedPool
.destroy()
47 await dynamicPool
.destroy()