Sink.count
Counts all incoming elements until upstream terminates.
Signature
Description
Counts values emitted from the stream, the count is available through a Future
CompletionStage
or which completes when the stream completes.
Example
Given a stream of numbers we can count the numbers with the count
operator
- Scala
-
source
val source = Source(1 to 10) val result = source.runWith(Sink.count) val count = result.futureValue println(count) // will print // 10
- Java
-
source
Source<Integer, NotUsed> ints = Source.range(1, 10); CompletionStage<Long> count = ints.runWith(Sink.count(), system); count.thenAccept(System.out::println); // 10
Reactive Streams semantics
completes when upstream completes
backpressures never (counting is a lightweight operation)
cancels never
2.0.0-M0+208-8bcc6969*