Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "subs/post-worker"

Index

Functions

Functions

Const postWorker

  • postWorker<T>(worker: Worker | Blob | string, transfer?: boolean, terminate?: number): ISubscriber<T>
  • Creates a 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 ISubscriber.done.

    example
    // worker source code
    src = `self.onmessage = (e) => console.log("worker", e.data);`;
    
    a = stream();
    a.subscribe(
      postWorker(src, { type: "application/javascript" }))
    );
    
    a.next(42)
    // worker 42

    Type parameters

    • T

    Parameters

    • worker: Worker | Blob | string

      -

    • Default value transfer: boolean = false

      -

    • Default value terminate: number = 0

      worker termination delay (ms)

    Returns ISubscriber<T>

Generated using TypeDoc