feat: smtp client pool example
[poolifier.git] / examples / typescript / smtp-client-pool / src / pool.ts
1 import { fileURLToPath } from 'node:url'
2 import { dirname, extname, join } from 'node:path'
3 import { DynamicThreadPool, availableParallelism } from 'poolifier'
4 import { type WorkerData } 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 smtpClientPool = new DynamicThreadPool<WorkerData>(
12 1,
13 availableParallelism(),
14 workerFile,
15 {
16 enableTasksQueue: true,
17 tasksQueueOptions: {
18 concurrency: 8
19 },
20 errorHandler: (e: Error) => {
21 console.error('Thread worker error:', e)
22 }
23 }
24 )