fromJavaStream
Stream the values from a Java 8 Stream
, requesting the next value when there is demand.
Signature
StreamConverters.fromJavaStream
StreamConverters.fromJavaStream
Description
Stream the values from a Java 8 Stream
, requesting the next value when there is demand. The iterator will be created anew for each materialization, which is the reason the method
factory
takes a function
Creator
rather than an Stream
directly.
You can use Source.async
to create asynchronous boundaries between synchronous java stream and the rest of flow.
Example
- Scala
-
source
Source.fromJavaStream(() => IntStream.rangeClosed(1, 3)).runForeach(println) // could print // 1 // 2 // 3
- Java
-
source
Source.fromJavaStream(() -> IntStream.rangeClosed(1, 3)) .runForeach(System.out::println, system); // could print // 1 // 2 // 3
Reactive Streams semantics
emits the next value returned from the iterator
completes when the iterator reaches its end
1.0.3