import { availableParallelism } from 'poolifier'
-import type { WorkerResponse } from './types.js'
+import type { WorkerData } from './types.js'
import { httpClientPool } from './pool.js'
const requestUrl = 'http://localhost:8080/'
for (const workerFunction of ['node_fetch', 'fetch', 'axios']) {
- const httpClientPoolPromises = new Set<Promise<WorkerResponse>>()
+ const httpClientRequests = new Set<WorkerData>()
for (let i = 0; i < parallelism; i++) {
- httpClientPoolPromises.add(
- httpClientPool.execute({ input: requestUrl }, workerFunction)
- )
+ httpClientRequests.add({ input: requestUrl })
}
try {
const now = performance.now()
- const responses = await Promise.all(httpClientPoolPromises)
+ const responses = await httpClientPool.mapExecute(
+ httpClientRequests,
+ workerFunction
+ )
const elapsedTime = performance.now() - now
console.info(
`Received in ${elapsedTime.toFixed(
-import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
+import type { WorkerData } from './types.js'
import { smtpClientPool } from './pool.js'
const tos = ['bar@example.com, baz@example.com']
-const smtpClientPoolPromises = new Set<Promise<SMTPTransport.SentMessageInfo>>()
+const smtpMessages = new Set<WorkerData>()
for (const to of tos) {
- smtpClientPoolPromises.add(
- smtpClientPool.execute({
- mail: {
- from: '"Foo" <foo@domain.tld>',
- html: '<b>Hello world?</b>',
- subject: 'Hello',
- text: 'Hello world?',
- to,
+ smtpMessages.add({
+ mail: {
+ from: '"Foo" <foo@domain.tld>',
+ html: '<b>Hello world?</b>',
+ subject: 'Hello',
+ text: 'Hello world?',
+ to,
+ },
+ smtpTransport: {
+ auth: {
+ pass: 'REPLACE-WITH-YOUR-GENERATED-PASSWORD',
+ user: 'REPLACE-WITH-YOUR-ALIAS@DOMAIN.TLD',
},
- smtpTransport: {
- auth: {
- pass: 'REPLACE-WITH-YOUR-GENERATED-PASSWORD',
- user: 'REPLACE-WITH-YOUR-ALIAS@DOMAIN.TLD',
- },
- host: 'smtp.domain.tld',
- port: 465,
- secure: true,
- },
- })
- )
+ host: 'smtp.domain.tld',
+ port: 465,
+ secure: true,
+ },
+ })
}
+
try {
const now = performance.now()
- await Promise.all(smtpClientPoolPromises)
+ await smtpClientPool.mapExecute(smtpMessages)
const elapsedTime = performance.now() - now
console.info(
`Send in parallel in ${elapsedTime.toFixed(