From 8162986eb9aff717ad56bed372abd6c63fe2a31d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 30 Aug 2024 18:03:10 +0200 Subject: [PATCH] docs: switch to `mapExecute()` in examples MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../typescript/http-client-pool/src/main.ts | 13 +++--- .../typescript/smtp-client-pool/src/main.ts | 43 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/examples/typescript/http-client-pool/src/main.ts b/examples/typescript/http-client-pool/src/main.ts index 1103c4ef..9848d21f 100644 --- a/examples/typescript/http-client-pool/src/main.ts +++ b/examples/typescript/http-client-pool/src/main.ts @@ -1,6 +1,6 @@ import { availableParallelism } from 'poolifier' -import type { WorkerResponse } from './types.js' +import type { WorkerData } from './types.js' import { httpClientPool } from './pool.js' @@ -8,15 +8,16 @@ const parallelism = availableParallelism() * 2 const requestUrl = 'http://localhost:8080/' for (const workerFunction of ['node_fetch', 'fetch', 'axios']) { - const httpClientPoolPromises = new Set>() + const httpClientRequests = new Set() 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( diff --git a/examples/typescript/smtp-client-pool/src/main.ts b/examples/typescript/smtp-client-pool/src/main.ts index f9f4d78e..a06a800c 100644 --- a/examples/typescript/smtp-client-pool/src/main.ts +++ b/examples/typescript/smtp-client-pool/src/main.ts @@ -1,35 +1,34 @@ -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>() +const smtpMessages = new Set() for (const to of tos) { - smtpClientPoolPromises.add( - smtpClientPool.execute({ - mail: { - from: '"Foo" ', - html: 'Hello world?', - subject: 'Hello', - text: 'Hello world?', - to, + smtpMessages.add({ + mail: { + from: '"Foo" ', + html: 'Hello world?', + 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( -- 2.34.1