mdedetrich commented on code in PR #2244:
URL: https://github.com/apache/pekko/pull/2244#discussion_r2365578981
##########
stream/src/main/scala/org/apache/pekko/stream/javadsl/Sink.scala:
##########
@@ -313,6 +313,27 @@ object Sink {
scaladsl.Sink.seq[In].mapMaterializedValue(fut => fut.map(sq =>
sq.asJava)(ExecutionContext.parasitic).asJava))
}
+ /**
+ * A `Sink` that counts all incoming elements until upstream terminates.
+ *
+ * Since upstream may be unbounded, consider using `Flow[T].take` or the
stricter `Flow[T].limit`
+ * (and their variants) to ensure boundedness. The sink materializes into a
`CompletionStage` of `Long`
+ * containing the total count of elements that passed through.
+ *
+ * '''Completes when''' upstream completes
+ *
+ * '''Backpressures when''' never (counting is a lightweight operation)
+ *
+ * '''Cancels when''' never
+ *
+ * @return a `Sink` that materializes to a `CompletionStage[Long]` with the
element count
+ * @since 2.0.0
+ *
+ * See also [[Flow.limit]], [[Flow.limitWeighted]], [[Flow.take]],
[[Flow.takeWithin]], [[Flow.takeWhile]]
+ */
+ def count[In]: Sink[In, CompletionStage[java.lang.Long]] = new Sink(
+
scaladsl.Sink.count[In].mapMaterializedValue(_.mapTo[java.lang.Long].asJava))
Review Comment:
iirc A Scala long can be used in Java fine (and Java sees a Scala long as a
Java long) but it doesn't work the other way around.
In other words just return Scala long in both Java and Scala dsl, you can
also look at other code for reference
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]