1 import { dirname
, extname
, join
} from
'path'
2 import { fileURLToPath
} from
'url'
3 import type { MyData
, MyResponse
} from
'./worker'
9 import type { MyData
, MyResponse
} from
'./worker'
11 const workerFile
= join(
12 dirname(fileURLToPath(import.meta
.url
)),
13 `worker${extname(fileURLToPath(import.meta.url))}`
16 export const fixedPool
= new FixedThreadPool
<MyData
, Promise
<MyResponse
>>(
17 availableParallelism(),
20 errorHandler
: (e
: Error) => {
23 onlineHandler
: () => {
24 console
.info('Worker is online')
29 export const dynamicPool
= new DynamicThreadPool
<MyData
, Promise
<MyResponse
>>(
30 Math.floor(availableParallelism() / 2),
31 availableParallelism(),
34 errorHandler
: (e
: Error) => {
37 onlineHandler
: () => {
38 console
.info('Worker is online')