refactor: add response type to SMTP client pool example
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 15 Aug 2023 09:40:07 +0000 (11:40 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 15 Aug 2023 09:40:07 +0000 (11:40 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
examples/typescript/smtp-client-pool/src/main.ts
examples/typescript/smtp-client-pool/src/pool.ts
examples/typescript/smtp-client-pool/src/worker.ts

index 70b1cb244cbdc7988d9e038533e354061106288b..1b463fa0b83ed257c6ec217b1da31de766ed8120 100644 (file)
@@ -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<Promise<unknown>>()
+const smtpClientPoolPromises = new Set<Promise<SMTPTransport.SentMessageInfo>>()
 for (const to of tos) {
   smtpClientPoolPromises.add(
     smtpClientPool.execute({
index f73094471fb017a3d385e5561168b7b38b5f2a21..ec2ec1367c5f0219dd8f685d3977e1f61d0ddf7a 100644 (file)
@@ -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<WorkerData>(
-  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)
   }
-)
+})
index a6026e4b6c8e60b21c0fba1b6bd7e56e242a2efb..3ac62ccac60ecf7ffd2fb75d04c35e06a7303872 100644 (file)
@@ -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<WorkerData> {
+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
         )
       }