StreamConverters.javaCollectorParallelUnordered

Create a sink which materializes into a Future CompletionStage which will be completed with a result of the Java Collector transformation and reduction operations.

Additional Sink and Source converters

Signature

StreamConverters.javaCollectorParallelUnorderedStreamConverters.javaCollectorParallelUnordered

Description

javaCollectorParallelUnordered creates a SinkSink that accepts a factory for a Java java.util.stream.Collector and processes incoming elements in parallel. The elements are distributed over parallelism workers using a Balance, so there is no guarantee about which worker receives which element, and the relative order of the elements is not preserved. Each worker runs asynchronously and accumulates the elements it receives into its own mutable result container created by the Collector. After the stream completes, the partial results are merged using the Collector’s combiner and transformed by its finisher. The sink materializes into a FutureCompletionStage holding the final result.

Because the order of the elements is not preserved, only use this with a Collector whose result does not depend on the order in which elements are accumulated and combined. If parallelism is 1 this behaves exactly like javaCollector.

Since a stream can be materialized multiple times, the function producing the Collector must be able to handle multiple invocations.