From: Jérôme Benoit Date: Tue, 15 Aug 2023 09:40:07 +0000 (+0200) Subject: refactor: add response type to SMTP client pool example X-Git-Tag: v2.6.26~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f83745944c9604776dceed8361b665d48a90bb79;p=poolifier.git refactor: add response type to SMTP client pool example Signed-off-by: Jérôme Benoit --- diff --git a/examples/typescript/smtp-client-pool/src/main.ts b/examples/typescript/smtp-client-pool/src/main.ts index 70b1cb24..1b463fa0 100644 --- a/examples/typescript/smtp-client-pool/src/main.ts +++ b/examples/typescript/smtp-client-pool/src/main.ts @@ -1,8 +1,9 @@ +import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js' import { smtpClientPool } from './pool.js' const tos = ['bar@example.com, baz@example.com'] -const smtpClientPoolPromises = new Set>() +const smtpClientPoolPromises = new Set>() for (const to of tos) { smtpClientPoolPromises.add( smtpClientPool.execute({ diff --git a/examples/typescript/smtp-client-pool/src/pool.ts b/examples/typescript/smtp-client-pool/src/pool.ts index f7309447..ec2ec136 100644 --- a/examples/typescript/smtp-client-pool/src/pool.ts +++ b/examples/typescript/smtp-client-pool/src/pool.ts @@ -1,6 +1,7 @@ import { fileURLToPath } from 'node:url' import { dirname, extname, join } from 'node:path' import { DynamicThreadPool, availableParallelism } from 'poolifier' +import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js' import { type WorkerData } from './types.js' const workerFile = join( @@ -8,17 +9,15 @@ const workerFile = join( `worker${extname(fileURLToPath(import.meta.url))}` ) -export const smtpClientPool = new DynamicThreadPool( - 1, - availableParallelism(), - workerFile, - { - enableTasksQueue: true, - tasksQueueOptions: { - concurrency: 8 - }, - errorHandler: (e: Error) => { - console.error('Thread worker error:', e) - } +export const smtpClientPool = new DynamicThreadPool< +WorkerData, +SMTPTransport.SentMessageInfo +>(1, availableParallelism(), workerFile, { + enableTasksQueue: true, + tasksQueueOptions: { + concurrency: 8 + }, + errorHandler: (e: Error) => { + console.error('Thread worker error:', e) } -) +}) diff --git a/examples/typescript/smtp-client-pool/src/worker.ts b/examples/typescript/smtp-client-pool/src/worker.ts index a6026e4b..3ac62cca 100644 --- a/examples/typescript/smtp-client-pool/src/worker.ts +++ b/examples/typescript/smtp-client-pool/src/worker.ts @@ -1,13 +1,17 @@ import { ThreadWorker } from 'poolifier' import { createTransport } from 'nodemailer' import type Mail from 'nodemailer/lib/mailer/index.js' +import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js' import { type WorkerData } from './types.js' -class SmtpClientWorker extends ThreadWorker { +class SmtpClientWorker extends ThreadWorker< +WorkerData, +SMTPTransport.SentMessageInfo +> { public constructor () { super({ nodemailer: async (workerData?: WorkerData) => { - await createTransport(workerData?.smtpTransport).sendMail( + return await createTransport(workerData?.smtpTransport).sendMail( workerData?.mail as Mail.Options ) }