Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ForkJoinOpts<IN, MSG, RES, OUT>

Type parameters

  • IN

  • MSG

  • RES

  • OUT

Hierarchy

  • {}
    • ForkJoinOpts

Index

Properties

Optional backPressure

backPressure: undefined | 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...

fork

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

Optional interrupt

interrupt: undefined | false | true

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

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.

Optional numWorkers

numWorkers: undefined | 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).

src

Input stream to attach to obtain work items from.

Optional terminate

terminate: undefined | 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

Optional transferables

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

worker: string | Worker | Blob

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