-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add AutoCloseable shortcut on mapWithResource #1053
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Thank you.
|
fa4ebb8
to
57cc873
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Can't wait to use this on may daily job |
I submitted CLA agreement PDF by email~ I'll share you when I got reply. |
stream-tests/src/test/java/org/apache/pekko/stream/javadsl/FlowTest.java
Outdated
Show resolved
Hide resolved
stream/src/main/scala/org/apache/pekko/stream/javadsl/Flow.scala
Outdated
Show resolved
Hide resolved
stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/FlowMapWithResourceSpec.scala
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raised an issue - I think the tests should ensure that the close runs after the map function.
57cc873
to
31f0dc9
Compare
Thanks for quick review! I'm struggling with build failure on my local env, |
@injae-kim I think you can update the |
stream-tests/src/test/java/org/apache/pekko/stream/javadsl/FlowTest.java
Outdated
Show resolved
Hide resolved
stream-tests/src/test/java/org/apache/pekko/stream/javadsl/SourceTest.java
Outdated
Show resolved
Hide resolved
stream-tests/src/test/java/org/apache/pekko/stream/javadsl/FlowTest.java
Show resolved
Hide resolved
stream/src/main/scala/org/apache/pekko/stream/javadsl/Source.scala
Outdated
Show resolved
Hide resolved
@injae-kim In very good shape, just need another update, thanks. |
Now I can build&run test on my local 😃 I also got email that my ICLA is received well~! Thanks a lot for your help! |
87192f8
to
f2e77c3
Compare
public void mustBeAbleToUseMapWithAutoCloseableResource() { | ||
final TestKit probe = new TestKit(system); | ||
final AtomicInteger closed = new AtomicInteger(); | ||
Source.from(Arrays.asList("1", "2", "3")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want add something like Flux.elements
for java dsl...
stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/FlowMapWithResourceSpec.scala
Show resolved
Hide resolved
f2e77c3
to
63d191f
Compare
Yeah, that's true, But we are not using Scala 2.13, maybe a conditional compiling can help us add that and I checked the fs2 : /** Converts the supplied [[java.lang.AutoCloseable]] into a singleton stream. */
def fromAutoCloseable[F[_]: Sync, O <: AutoCloseable](fo: F[O]): Stream[F, O] =
Stream.resource(Resource.fromAutoCloseable(fo)) |
stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/FlowMapWithResourceSpec.scala
Outdated
Show resolved
Hide resolved
stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/FlowMapWithResourceSpec.scala
Show resolved
Hide resolved
@injae-kim Thank you ,seems you will just need a final update and then looks good to me. as @mdedetrich , I think that's will not be a problem, because Even |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@Roiocam ping for additional CR, as a Java CRUD guy, I love this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks
docs/src/main/paradox/stream/operators/Source-or-Flow/mapWithResource.md
Outdated
Show resolved
Hide resolved
docs/src/main/paradox/stream/operators/Source-or-Flow/mapWithResource.md
Show resolved
Hide resolved
67a1c57
to
7200322
Compare
@pjfanning Would you like give this another round review? |
old review - I don't have time this afternoon to re-review
@@ -2541,6 +2541,45 @@ final class Source[Out, Mat](delegate: scaladsl.Source[Out, Mat]) extends Graph[ | |||
(resource, out) => f(resource, out), | |||
resource => close.apply(resource).toScala)) | |||
|
|||
/** | |||
* Transform each stream element with the help of a [[AutoCloseable]] resource and close it when the stream finishes or fails. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ updated. oh thanks for catching!
stream/src/main/scala/org/apache/pekko/stream/javadsl/Flow.scala
Outdated
Show resolved
Hide resolved
stream/src/main/scala/org/apache/pekko/stream/javadsl/SubFlow.scala
Outdated
Show resolved
Hide resolved
stream/src/main/scala/org/apache/pekko/stream/javadsl/SubSource.scala
Outdated
Show resolved
Hide resolved
stream/src/main/scala/org/apache/pekko/stream/scaladsl/Flow.scala
Outdated
Show resolved
Hide resolved
@injae-kim Good afternoon, seems only the last typo need to change, do you have any further improvement, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Thank you @injae-kim |
Thank you to all reviewers! without your kind helps, I wouldn't have created this PR :) I'll continue to contribute on pekko with another PR 🚀 |
Motivation
mapwithResource
now, would be better to supportAutoCloseable
in Java/Scala dsl too.Modification
AutoCloseable
shortcut onmapWithResource
Result
mapWithResource
will close theAutoCloseable
so user don't need to pass close function