From: Jérôme Benoit Date: Fri, 30 Aug 2024 16:03:10 +0000 (+0200) Subject: docs: switch to `mapExecute()` in examples X-Git-Tag: v4.2.10~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8162986eb9aff717ad56bed372abd6c63fe2a31d;p=poolifier.git docs: switch to `mapExecute()` in examples Signed-off-by: Jérôme Benoit --- 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(