Sink.head
Materializes into a Future
CompletionStage
which completes with the first value arriving, after this the stream is canceled.
Signature
Description
Materializes into a Future
CompletionStage
which completes with the first value arriving, after this the stream is canceled. If no element is emitted, the Future
CompletionStage
is failed.
Example
- Scala
-
source
val source = Source(1 to 10) val result: Future[Int] = source.runWith(Sink.head) result.map(println) // 1
- Java
-
source
Source<Integer, NotUsed> source = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); CompletionStage<Integer> result = source.runWith(Sink.head(), system); result.thenAccept(System.out::println); // 1
Reactive Streams semantics
cancels after receiving one element
backpressures never
1.1.2+24-bcd44ee3*