1 import { dirname
, extname
, join
} from
'path'
2 import { fileURLToPath
} from
'url'
3 import type { MyData
, MyResponse
} from
'./worker'
10 const workerFile
= join(
11 dirname(fileURLToPath(import.meta
.url
)),
12 `worker${extname(fileURLToPath(import.meta.url))}`
15 export const fixedPool
= new FixedThreadPool
<MyData
, Promise
<MyResponse
>>(
16 availableParallelism(),
19 errorHandler
: (e
: Error) => {
22 onlineHandler
: () => {
23 console
.info('Worker is online')
28 export const dynamicPool
= new DynamicThreadPool
<MyData
, Promise
<MyResponse
>>(
29 Math.floor(availableParallelism() / 2),
30 availableParallelism(),
33 errorHandler
: (e
: Error) => {
36 onlineHandler
: () => {
37 console
.info('Worker is online')