Skip to content

UseCreatePool

katanakit-js / 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 Parameter Description
TInput Input data type.
TOutput Output data type.
Parameter Type Description
key string A unique identifier for this pool.
workerFunc WorkerFunc<TInput, TOutput> The pure function the pool will execute.

void

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