You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pekko.apache.org by he...@apache.org on 2025/08/02 06:48:40 UTC
(pekko) branch main updated: =str Switch the type parameter order of UnfoldResourceSourceAsync (#616)
This is an automated email from the ASF dual-hosted git repository.
hepin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 7bf6cf4969 =str Switch the type parameter order of UnfoldResourceSourceAsync (#616)
7bf6cf4969 is described below
commit 7bf6cf49696ec2ac3501d17f118753927ec209da
Author: He-Pin(kerr) <he...@gmail.com>
AuthorDate: Sat Aug 2 14:48:35 2025 +0800
=str Switch the type parameter order of UnfoldResourceSourceAsync (#616)
---
.../pekko/stream/impl/UnfoldResourceSourceAsync.scala | 14 +++++++-------
.../scala/org/apache/pekko/stream/javadsl/Source.scala | 16 +++++++++-------
.../scala/org/apache/pekko/stream/scaladsl/Source.scala | 10 ++++++----
3 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/stream/src/main/scala/org/apache/pekko/stream/impl/UnfoldResourceSourceAsync.scala b/stream/src/main/scala/org/apache/pekko/stream/impl/UnfoldResourceSourceAsync.scala
index 6f6c186186..f7a6719b48 100644
--- a/stream/src/main/scala/org/apache/pekko/stream/impl/UnfoldResourceSourceAsync.scala
+++ b/stream/src/main/scala/org/apache/pekko/stream/impl/UnfoldResourceSourceAsync.scala
@@ -31,10 +31,10 @@ import pekko.util.OptionVal
/**
* INTERNAL API
*/
-@InternalApi private[pekko] final class UnfoldResourceSourceAsync[T, S](
- create: () => Future[S],
- readData: (S) => Future[Option[T]],
- close: (S) => Future[Done])
+@InternalApi private[pekko] final class UnfoldResourceSourceAsync[R, T](
+ create: () => Future[R],
+ readData: (R) => Future[Option[T]],
+ close: (R) => Future[Done])
extends GraphStage[SourceShape[T]] {
val out = Outlet[T]("UnfoldResourceSourceAsync.out")
override val shape = SourceShape(out)
@@ -45,9 +45,9 @@ import pekko.util.OptionVal
new GraphStageLogic(shape) with OutHandler {
private lazy val decider = inheritedAttributes.mandatoryAttribute[SupervisionStrategy].decider
private implicit def ec: ExecutionContext = materializer.executionContext
- private var maybeResource: OptionVal[S] = OptionVal.none
+ private var maybeResource: OptionVal[R] = OptionVal.none
- private val createdCallback = getAsyncCallback[Try[S]] {
+ private val createdCallback = getAsyncCallback[Try[R]] {
case Success(resource) =>
require(resource != null, "`create` method should not return a null resource.")
maybeResource = OptionVal(resource)
@@ -134,7 +134,7 @@ import pekko.util.OptionVal
createdCallback(resource).failed.foreach {
case _: StreamDetachedException =>
// stream stopped before created callback could be invoked, we need
- // to close the resource if it is was opened, to not leak it
+ // to close the resource if it was opened, to not leak it
resource match {
case Success(r) =>
close(r)
diff --git a/stream/src/main/scala/org/apache/pekko/stream/javadsl/Source.scala b/stream/src/main/scala/org/apache/pekko/stream/javadsl/Source.scala
index df617695d8..0e5025ce8c 100755
--- a/stream/src/main/scala/org/apache/pekko/stream/javadsl/Source.scala
+++ b/stream/src/main/scala/org/apache/pekko/stream/javadsl/Source.scala
@@ -960,16 +960,18 @@ object Source {
* @param read - function that reads data from opened resource. It is called each time backpressure signal
* is received. Stream calls close and completes when `CompletionStage` from read function returns an empty Optional.
* @param close - function that closes resource
+ * @tparam T the element type
+ * @tparam R the resource type
*/
- def unfoldResourceAsync[T, S](
- create: function.Creator[CompletionStage[S]],
- read: function.Function[S, CompletionStage[Optional[T]]],
- close: function.Function[S, CompletionStage[Done]]): javadsl.Source[T, NotUsed] =
+ def unfoldResourceAsync[T, R](
+ create: function.Creator[CompletionStage[R]],
+ read: function.Function[R, CompletionStage[Optional[T]]],
+ close: function.Function[R, CompletionStage[Done]]): javadsl.Source[T, NotUsed] =
new Source(
- scaladsl.Source.unfoldResourceAsync[T, S](
+ scaladsl.Source.unfoldResourceAsync[T, R](
() => create.create().asScala,
- (s: S) => read.apply(s).asScala.map(_.toScala)(pekko.dispatch.ExecutionContexts.parasitic),
- (s: S) => close.apply(s).asScala))
+ (resource: R) => read.apply(resource).asScala.map(_.toScala)(pekko.dispatch.ExecutionContexts.parasitic),
+ (resource: R) => close.apply(resource).asScala))
/**
* Upcast a stream of elements to a stream of supertypes of that element. Useful in combination with
diff --git a/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala b/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala
index 16d80baa36..aab2ce3f78 100644
--- a/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala
+++ b/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala
@@ -1098,11 +1098,13 @@ object Source {
* @param read - function that reads data from opened resource. It is called each time backpressure signal
* is received. Stream calls close and completes when `Future` from read function returns None.
* @param close - function that closes resource
+ * @tparam T the element type
+ * @tparam R the resource type
*/
- def unfoldResourceAsync[T, S](
- create: () => Future[S],
- read: (S) => Future[Option[T]],
- close: (S) => Future[Done]): Source[T, NotUsed] =
+ def unfoldResourceAsync[T, R](
+ create: () => Future[R],
+ read: (R) => Future[Option[T]],
+ close: (R) => Future[Done]): Source[T, NotUsed] =
Source.fromGraph(new UnfoldResourceSourceAsync(create, read, close))
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pekko.apache.org
For additional commands, e-mail: commits-help@pekko.apache.org