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