Merge branch 'master' into worker-info
[poolifier.git] / examples / typescript / pool.ts
1 import { join } from 'path'
2 import type { MyData, MyResponse } from './worker'
3 import {
4 DynamicThreadPool,
5 FixedThreadPool,
6 availableParallelism
7 } from 'poolifier'
8
9 export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
10 availableParallelism(),
11 join(__dirname, 'worker.js'),
12 {
13 errorHandler: (e: Error) => {
14 console.error(e)
15 },
16 onlineHandler: () => {
17 console.info('Worker is online')
18 }
19 }
20 )
21
22 export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
23 availableParallelism() / 2,
24 availableParallelism(),
25 join(__dirname, 'worker.js'),
26 {
27 errorHandler: (e: Error) => {
28 console.error(e)
29 },
30 onlineHandler: () => {
31 console.info('Worker is online')
32 }
33 }
34 )