Skip to content

Function: seize()

seize<T, R>(task, onMessage, onError): Stream<SeizedWorker<any, any>>

Defined in: streams/seize.ts:51

Creates a stream that "seizes" a single worker from the coroutine pool, providing a persistent, manually-controlled communication channel.

This operator is ideal for scenarios where you need to perform multiple, sequential tasks on a specific, stateful worker. The worker remains dedicated to the returned stream until the release() method is called on the SeizedWorker object.

The stream itself will only emit a single SeizedWorker object and then complete after the worker has been released.

Type Parameters

T

T = any

The type of data sent to the worker.

R

R = T

The type of data returned from the worker.

Parameters

task

Coroutine<T, R>

The coroutine instance managing the worker pool.

onMessage

(message) => void

A callback function to handle messages received from the seized worker.

onError

(error) => void

A callback function to handle errors originating from the seized worker.

Returns

Stream<SeizedWorker<any, any>>

A stream that yields a single SeizedWorker object.

Released under the MIT License.