| 1 | import { join } from 'path' |
| 2 | import type { MyData, MyResponse } from './worker' |
| 3 | import { DynamicThreadPool, FixedThreadPool } from 'poolifier' |
| 4 | |
| 5 | export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>( |
| 6 | 8, |
| 7 | join(__dirname, 'worker.js'), |
| 8 | { |
| 9 | errorHandler: (e: Error) => { |
| 10 | console.error(e) |
| 11 | }, |
| 12 | onlineHandler: () => { |
| 13 | console.log('Worker is online') |
| 14 | } |
| 15 | } |
| 16 | ) |
| 17 | |
| 18 | export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>( |
| 19 | 2, |
| 20 | 8, |
| 21 | join(__dirname, 'worker.js'), |
| 22 | { |
| 23 | errorHandler: (e: Error) => { |
| 24 | console.error(e) |
| 25 | }, |
| 26 | onlineHandler: () => { |
| 27 | console.log('Worker is online') |
| 28 | } |
| 29 | } |
| 30 | ) |