Commit | Line | Data |
---|---|---|
11856b30 JB |
1 | import { fileURLToPath } from 'node:url' |
2 | import { dirname, extname, join } from 'node:path' | |
3 | import { FixedThreadPool, 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 fetchPool = new FixedThreadPool<WorkerData, WorkerResponse>( | |
12 | availableParallelism(), | |
13 | workerFile, | |
14 | { | |
15 | enableTasksQueue: true, | |
16 | errorHandler: (e: Error) => { | |
17 | console.error(e) | |
18 | } | |
19 | } | |
20 | ) |