Skip to content

Function: coroutine()

Call Signature

coroutine(config): <T, R>(main, ...functions) => Coroutine<T, R>

Defined in: operators/coroutine.ts:203

Creates a coroutine operator for managing a pool of Web Workers.

This function has two overloaded signatures:

  1. coroutine(config): Returns a factory function that takes a main task and helper functions.
  2. coroutine(mainTask, ...helpers): Directly creates a coroutine operator with a default configuration.

This operator is a powerful tool for offloading computationally intensive tasks from the main thread, allowing for concurrent processing of stream data without blocking the UI. It manages a pool of workers, dynamically scaling up to navigator.hardwareConcurrency and reusing workers to minimize overhead.

Parameters

config

CoroutineConfig

The configuration object for the worker pool.

Returns

A higher-order function for creating a Coroutine operator.

<T, R>(main, ...functions): Coroutine<T, R>

Type Parameters

T

T

R

R

Parameters

main

MainTask<T, R>

functions

...Function[]

Returns

Coroutine<T, R>

Call Signature

coroutine<T, R>(main, ...functions): Coroutine<T, R>

Defined in: operators/coroutine.ts:213

Creates a coroutine operator with a default configuration.

Type Parameters

T

T

The type of the input data for the main task.

R

R

The type of the return value from the main task.

Parameters

main

MainTask<T, R>

The main task function to run inside the workers.

functions

...Function[]

Any helper functions required by the main task.

Returns

Coroutine<T, R>

A Coroutine operator.

Released under the MIT License.