build: add missing JSON schema to package.json
[poolifier.git] / examples / typescript / pool.ts
... / ...
CommitLineData
1import { dirname, join } from 'path'
2import { fileURLToPath } from 'url'
3import type { MyData, MyResponse } from './worker'
4import {
5 DynamicThreadPool,
6 FixedThreadPool,
7 availableParallelism
8} from 'poolifier'
9
10export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
11 availableParallelism(),
12 join(dirname(fileURLToPath(import.meta.url)), 'worker.js'),
13 {
14 errorHandler: (e: Error) => {
15 console.error(e)
16 },
17 onlineHandler: () => {
18 console.info('Worker is online')
19 }
20 }
21)
22
23export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
24 Math.floor(availableParallelism() / 2),
25 availableParallelism(),
26 join(dirname(fileURLToPath(import.meta.url)), 'worker.js'),
27 {
28 errorHandler: (e: Error) => {
29 console.error(e)
30 },
31 onlineHandler: () => {
32 console.info('Worker is online')
33 }
34 }
35)