refactor: use zero sized dynamic pool in examples
[poolifier.git] / examples / typescript / smtp-client-pool / src / pool.ts
CommitLineData
9aef1431
JB
1import { fileURLToPath } from 'node:url'
2import { dirname, extname, join } from 'node:path'
3import { DynamicThreadPool, availableParallelism } from 'poolifier'
f8374594 4import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
ef083f7b 5import type { WorkerData } from './types.js'
9aef1431
JB
6
7const workerFile = join(
8 dirname(fileURLToPath(import.meta.url)),
9 `worker${extname(fileURLToPath(import.meta.url))}`
10)
11
f8374594
JB
12export const smtpClientPool = new DynamicThreadPool<
13WorkerData,
14SMTPTransport.SentMessageInfo
0fce423d 15>(0, availableParallelism(), workerFile, {
f8374594
JB
16 enableTasksQueue: true,
17 tasksQueueOptions: {
18 concurrency: 8
19 },
20 errorHandler: (e: Error) => {
21 console.error('Thread worker error:', e)
9aef1431 22 }
f8374594 23})