Skip to content
0

katanakit-js / useCreatePool

Function: useCreatePool() ​

ts
function useCreatePool<TInput, TOutput>(key, workerFunc): void;

Defined in: src/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 ​

Type ParameterDescription
TInputInput data type.
TOutputOutput data type.

Parameters ​

ParameterTypeDescription
keystringA unique identifier for this pool.
workerFuncWorkerFunc<TInput, TOutput>The pure function the pool will execute.

Returns ​

void

Example ​

ts
useCreatePool("heavy", (n: number) => n ** 2);
const result = await useRunPool("heavy", 9); // 81
useTerminate("heavy");

Released under the MIT License.