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