Interface ForkJoinOpts<IN, MSG, RES, OUT>

interface ForkJoinOpts<IN, MSG, RES, OUT> {
    backPressure?: number;
    cache?: boolean;
    closeIn?: CloseMode;
    closeOut?: CloseMode;
    fork: Fn3<number, number, IN, MSG>;
    id?: string;
    interrupt?: boolean;
    join: Fn<RES[], OUT>;
    numWorkers?: number;
    src: ITransformable<IN>;
    terminate?: number;
    transferables?: Fn<MSG, any[]>;
    worker: WorkerSource;
}

Type Parameters

  • IN
  • MSG
  • RES
  • OUT

Hierarchy

Properties

backPressure?: number

If greater than 0, then each labeled input will cache upto the stated number of input values, even if other inputs have not yet produced new values. Once the limit is reached, partitionSync() will throw an IllegalState error.

Enabling this option will cause the same behavior as if reset is enabled (regardless of the actual configured reset setting). I.e. new results are only produced when ALL required inputs have available values...

cache?: boolean

If true (default), stream caches last received value and pushes it to new subscriberswhen they subscribe. If false, calling .deref() on this stream will always return undefined.

Default Value

true
closeIn?: CloseMode

If false or CloseMode.NEVER, the stream stays active even if all inputs are done. If true (default) or CloseMode.LAST, the stream closes when the last input is done. If CloseMode.FIRST, the instance closes when the first input is done.

Default Value

CloseMode.LAST
closeOut?: CloseMode

If false or CloseMode.NEVER, the stream stays active once there are no more subscribers. If true (default) or CloseMode.LAST, the stream closes when the last subscriber has unsubscribed. If CloseMode.FIRST, the instance closes when the first subscriber disconnects.

Default Value

CloseMode.LAST
fork: Fn3<number, number, IN, MSG>

Transformation function prepare (e.g. chunk) work for a single worker. Receives worker id [0 .. numWorkers), numWorkers and current input value to be processed. Only the results of this function are sent to the worker and therefore the function must return a type compatible with the configured worker instance.

For example, such a function might extract slices from a large input array, one per worker. The given worker ID and worker count can be used to create non-overlapping chunks to evenly spread the workload...

Also see: forkBuffer

id?: string

Internal ID associated with this stream. If omitted, an autogenerated ID will be used.

interrupt?: boolean

If true, the workers will be terminated and restarted for each new input stream value. This is useful to avoid executing extraneous work and ensures only the most rececent stream value is being processed.

IMPORTANT: Please note that forkJoin does NOT handle backpressure at all. If interrupt is false, it's the user's responsibility to ensure that the input stream does NOT operate on a higher frequency than workers can produce results or else undefined behavior WILL occur!

Default: false

join: Fn<RES[], OUT>

Join function. Receives array of worker results (in worker ID order) and is responsible to transform these into the final result / output type.

numWorkers?: number

Optional max number of workers to use. Defaults to navigator.hardwareConcurrency (or if unavailable, then 4 as fallback). If setting this higher, be aware of browser limits and potential resulting crashes!

If using multiple forkJoins concurrently, it's the user's responsibility to ensure that the total number of workers won't exceed the browser limit (Chome/FF ~20).

Input stream to attach to obtain work items from.

terminate?: number

If given and greater than zero, all workers will be terminated after given period (in millis) after the parent stream is done. If used, this value MUST be higher than the expected processing time of the worker jobs, in order to guarantee that the last values are processed fully.

Default: 1000

transferables?: Fn<MSG, any[]>

Optional function to extract transferables from fork result values (i.e. payloads sent to each worker), e.g. ArrayBuffers. See: https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage

worker: WorkerSource

An existing Worker instance, a JS source code Blob or an URL string. In the latter two cases, a worker is created automatically using makeWorker().

Generated using TypeDoc