UNPKG

@thi.ng/rstream

Version:

Reactive streams & subscription primitives for constructing dataflow graphs / pipelines

39 lines 1.37 kB
import type { ISubscriber } from "./api.js"; /** * Creates a {@link ISubscriber | subscriber} which forwards received * values to given worker. * * @remarks * The `worker` can be an existing `Worker` instance, a JS source code * `Blob` or an URL string. In the latter two cases, a worker is created * automatically. If `transfer` is true, the received values will be * marked as *transferrable* and the host app loses all access * permissions to these marked values. See `Worker.postMessage()` for * details. * * If `terminate` is set to a positive number, then the worker will be * automatically terminated after the stated number of milliseconds * since the parent subscription is {@link ISubscriber.done}. * * @example * ```ts tangle:../export/post-worker.ts * import { postWorker, stream } from "@thi.ng/rstream"; * * // worker source code * const src = `self.onmessage = (e) => console.log("worker", e.data);`; * * const a = stream<any>(); * a.subscribe( * postWorker(new Blob([src], { type: "application/javascript" })) * ); * * a.next(42) * // worker 42 * ``` * * @param worker - * @param transfer - * @param terminate - worker termination delay (ms) */ export declare const postWorker: <T>(worker: Worker | Blob | string, transfer?: boolean, terminate?: number) => ISubscriber<T>; //# sourceMappingURL=post-worker.d.ts.map