Skip to content

Function: compute()

compute<T>(task, params): Stream<T>

Defined in: streams/compute.ts:18

Creates a stream that runs a computation task on a worker from a Coroutine pool, yielding the result once the computation completes.

This operator is designed for offloading CPU-intensive tasks to a background thread, preventing the main thread from being blocked and keeping the UI responsive. It uses a Coroutine to manage a pool of web workers. The stream will emit a single value and then complete.

Type Parameters

T

T = any

The type of the result from the computation.

Parameters

task

Coroutine

The coroutine instance managing the worker pool.

params

any

The data to send to the worker for computation.

Returns

Stream<T>

A new stream that emits the result of the computation.

Released under the MIT License.