UNPKG

@thi.ng/rstream

Version:

Reactive streams & subscription primitives for constructing dataflow graphs / pipelines

74 lines 2.44 kB
import type { Fn, Fn0 } from "@thi.ng/api"; import { Subscription } from "./subscription.js"; export interface TunnelOpts<A> { /** * Tunnelled worker instance, source blob or script URL. * If `interrupt` is enabled, the worker MUST be given as blob or URL. */ src: Worker | Blob | string | Fn0<Worker>; /** * Max. number of worker instances to use. Only useful if * `interrupt` is disabled. If more than one worker is used, * incoming stream values will be assigned in a round robin manner * and result value ordering will be non-deterministic. Workers will * be instantiated on demand. * * Default: 1 */ maxWorkers?: number; /** * Optional subscription ID to use. */ id?: string; /** * Optional function to extract transferables from incoming stream values, * e.g. ArrayBuffers. See: * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage */ transferables?: Fn<A, any[]>; /** * If given and greater than zero, all workers will be terminated * after given period (in millis) after the parent stream is done. * * Default: 1000 */ terminate?: number; /** * If true, the worker will be terminated and restarted for each new * stream value. This is useful to avoid executing extraneous work * and ensures only the most rececent stream value is being processed. * * Default: false */ interrupt?: boolean; } /** * Returns a {@link Subscription} which processes received values via * the configured worker(s) and then passes values received back from * the worker(s) downstream, thereby allowing workers to be used * transparently for stream processing. * * @remarks * Multiple worker instances are supported for concurrent processing. * See the {@link TunnelOpts} for details. * * Also see {@link forkJoin} and {@link postWorker}. * * @param opts - */ export declare const tunnel: <A, B>(opts: TunnelOpts<A>) => Tunnel<A, B>; /** * See {@link tunnel} for reference & examples. */ export declare class Tunnel<A, B> extends Subscription<A, B> { workers: Worker[]; src: Worker | Blob | string | Fn0<Worker>; transferables?: Fn<A, any[]>; terminate: number; interrupt: boolean; index: number; constructor(opts: TunnelOpts<A>); next(x: A): void; done(): void; } //# sourceMappingURL=tunnel.d.ts.map