Commit | Line | Data |
---|---|---|
fac9ce96 JB |
1 | import { dirname, extname, join } from 'node:path' |
2 | import { fileURLToPath } from 'node:url' | |
3 | import { DynamicThreadPool, availableParallelism } from 'poolifier' | |
4 | import { type WorkerData, type WorkerResponse } from './types.js' | |
5 | ||
6 | const workerFile = join( | |
7 | dirname(fileURLToPath(import.meta.url)), | |
8 | `worker${extname(fileURLToPath(import.meta.url))}` | |
9 | ) | |
10 | ||
11 | export const requestHandlerPool = new DynamicThreadPool< | |
12 | WorkerData, | |
13 | WorkerResponse | |
14 | >(1, availableParallelism(), workerFile, { | |
15 | enableTasksQueue: true, | |
16 | tasksQueueOptions: { | |
17 | concurrency: 8 | |
18 | }, | |
19 | errorHandler: (e: Error) => { | |
20 | console.error(e) | |
21 | } | |
22 | }) |