UseCreatePool
katanakit-js / useCreatePool
Function: useCreatePool()
Section titled “Function: useCreatePool()”function useCreatePool<TInput, TOutput>(key, workerFunc): void;Defined in: infrastructure/worker/worker.service.ts:123
Creates a reusable Worker pool under a unique key. If a pool with the same key already exists, it is terminated first.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
TInput |
Input data type. |
TOutput |
Output data type. |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
key |
string |
A unique identifier for this pool. |
workerFunc |
WorkerFunc<TInput, TOutput> |
The pure function the pool will execute. |
Returns
Section titled “Returns”void
Example
Section titled “Example”useCreatePool("heavy", (n: number) => n ** 2);const result = await useRunPool("heavy", 9); // 81useTerminate("heavy");