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
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 function. Receives array of worker results (in worker ID order) and is responsible to transform these into the final result / output type.
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 forkJoin
s 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.
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 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
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
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 anIllegalState
error.Enabling this option will cause the same behavior as if
reset
is enabled (regardless of the actual configuredreset
setting). I.e. new results are only produced when ALL required inputs have available values...