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