docs: add `mapExecute` implementation to fastify examples plugin
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 30 Aug 2024 15:37:37 +0000 (17:37 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 30 Aug 2024 15:37:37 +0000 (17:37 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts
examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts

index ece9b8cf77456eecfc87c303c4d170351e1da59d..22a55053626a2736ece91ff7de469c7ccb02e34e 100644 (file)
@@ -45,6 +45,17 @@ const fastifyPoolifierPlugin: FastifyPluginCallback<FastifyPoolifierOptions> = (
         await pool.execute(data, name, transferList)
     )
   }
+  if (!fastify.hasDecorator('mapExecute')) {
+    fastify.decorate(
+      'mapExecute',
+      async (
+        data: Iterable<ThreadWorkerData>,
+        name?: string,
+        transferList?: readonly TransferListItem[]
+      ): Promise<ThreadWorkerResponse[]> =>
+        await pool.mapExecute(data, name, transferList)
+    )
+  }
   done()
 }
 
index a9156566ef6025ebf4799e21bbe7e7ba6cd7b7ec..0a92fe09117295f8b5a2e137f21ea81de00f7c0f 100644 (file)
@@ -44,6 +44,17 @@ const fastifyPoolifierPlugin: FastifyPluginCallback<FastifyPoolifierOptions> = (
       ): Promise<WorkerResponse> => await pool.execute(data, name, transferList)
     )
   }
+  if (!fastify.hasDecorator('mapExecute')) {
+    fastify.decorate(
+      'mapExecute',
+      async (
+        data: Iterable<WorkerData>,
+        name?: string,
+        transferList?: readonly TransferListItem[]
+      ): Promise<WorkerResponse[]> =>
+        await pool.mapExecute(data, name, transferList)
+    )
+  }
   done()
 }