@epikodelabs/streamix / coroutines/src/public-api / compute
Function: compute()
compute<
T,R>(main, ...functions):ComputeRunner<T,R>
Defined in: projects/libraries/streamix/coroutines/src/lib/factories/compute.ts:35
Offloads a function to a dedicated worker pool.
compute creates a specialized reusable pool: the task is baked into the worker blob once and shared by every worker in the pool. There is no runtime compilation overhead; workers are pre-initialized with the task.
The returned async function submits params to that pool. The pool lives for as long as the function exists. Call .dispose() when done to terminate the underlying workers.
Type Parameters
T
T = any
R
R = any
Parameters
main
(data) => R | Promise<R>
functions
...Function[]
Returns
ComputeRunner<T, R>
Example
ts
const run = compute((x: number) => x * 2);
const result = await run(5); // 10
await run.dispose();