fb48f7b07db76324a75afc001e131dd448a6809f
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 const fixedPool
= new FixedThreadPool
<MyData
, MyResponse
>(
18 availableParallelism(),
21 errorHandler
: (e
: Error) => {
24 onlineHandler
: () => {
25 console
.info('Worker is online')
30 await fixedPool
.execute()
32 const dynamicPool
= new DynamicThreadPool
<MyData
, MyResponse
>(
33 Math.floor(availableParallelism() / 2),
34 availableParallelism(),
37 errorHandler
: (e
: Error) => {
40 onlineHandler
: () => {
41 console
.info('Worker is online')
46 await dynamicPool
.execute()
48 // eslint-disable-next-line @typescript-eslint/no-misused-promises
49 setTimeout(async () => {
50 await fixedPool
.destroy()
51 await dynamicPool
.destroy()