Skip to content

Create Source from Sink #25150

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

Closed

Conversation

cedretaber
Copy link

Refs #24853

Add connect to Source.
It easily connects a source to a sink, based on #24853 (comment).

@lightbend-cla-validator

Hi @cedretaber,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Lightbend Contributors License Agreement:

http://www.lightbend.com/contribute/cla

@akka-ci
Copy link

akka-ci commented May 27, 2018

Thank you for your pull request! After a quick sanity check one of the team will reply with 'OK TO TEST' to kick off our automated validation on Jenkins. This compiles the project, runs the tests, and checks for things like binary compatibility and source code formatting. When two team members have also manually reviewed and (perhaps after asking for some amendments) accepted your contribution, it should be good to be merged.

For more details about our contributing process, check out CONTRIBUTING.md - and feel free to ask!

@johanandren
Copy link
Contributor

OK TO TEST

@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed validating PR is currently being validated by Jenkins labels May 29, 2018
@akka-ci
Copy link

akka-ci commented May 29, 2018

Test FAILed.

@johanandren
Copy link
Contributor

Seems the docs are misplaced, but let's discuss the design first:

  • Is it really a good idea to run the graph, I don't think any other factories takes a materializer and runs anything?
  • If we should run the graph, could we raise the abstraction level even further and take one side as a parameter to make it easier to use/understand?
  • I don't think connect or connection as in Heikos original version is a good name, to me it does not convey at all what it does. It would be better with something along the lines of fromSink, toSink, asSink, sinkToSource, sinkAndSource?
  • Additional design consideration does it really belongs on Source or if it would fit better on Sink or maybe even Flow given that it is sort of a flow?

@cedretaber
Copy link
Author

Thank you for your review!

  • Yes, it seems to make sense that there is no need to run the graph.
  • I have no idea what it's name is. However, I could feel that sinkAndSource is better.
  • As Flow has some methods which creates a flow from a sink and a source, it might be in Flow.

@johanandren
Copy link
Contributor

With regards to Flow that makes somewhat sense, but it isn't returning a Flow. Maybe it wouldn't be the first place you'd look if the reverse-adapter-thingie is what you are looking for.

I think I like Souce.sinkToSource best, for discoverability and saying what it does.

@akka-ci akka-ci added validating PR is currently being validated by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) labels May 30, 2018
@cedretaber cedretaber force-pushed the issue-24853-source-from-sink branch from df4b894 to 781d9d8 Compare May 30, 2018 15:48
@akka-ci akka-ci added needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed validating PR is currently being validated by Jenkins labels May 30, 2018
@akka-ci
Copy link

akka-ci commented May 30, 2018

Test FAILed.

@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels May 30, 2018
@akka-ci
Copy link

akka-ci commented May 30, 2018

Test FAILed.


@@@div { .callout }

@@@
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd need examples as well, from nowadays we should always right away include examples when we merge new operators. See here how: https://raw.githubusercontent.com/akka/akka/master/akka-docs/src/main/paradox/stream/operators/Sink/actorRefWithAck.md

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I create SourceDocSpec.scala , or write the tests in IntegrationDocSpec.scala ?

.toMat(Sink.asPublisher[M](fanout = false))(Keep.both)
.mapMaterializedValue {
case (sub, pub) ⇒ (Sink.fromSubscriber(sub), Source.fromPublisher(pub))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to get a javadsl as well, on javadsl.Source

* > Sink |------>| Source >
* +----------+ +----------+
*
* Should be provided by Akka Streams, see https://github.com/akka/akka/issues/24853.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for such comment, this is IN akka streams then after all ;-)

* +----------+ +----------+
* > Sink |------>| Source >
* +----------+ +----------+
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be put into a

{{{
...
}}}

for formatting reasons

.toMat(Sink.asPublisher[M](fanout = false))(Keep.both)
.mapMaterializedValue {
case (sub, pub) ⇒ (Sink.fromSubscriber(sub), Source.fromPublisher(pub))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks fine though :)

*
* Should be provided by Akka Streams, see https://github.com/akka/akka/issues/24853.
*/
def sinkToSource[M]: RunnableGraph[(Sink[M, NotUsed], Source[M, NotUsed])] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to ponder the name some more...
I have no good name today in mind though...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the best I can come up with

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the name: This seems like the opposite of Flow#fromSinkAndSource. It seems like this could live on Flow (the class not the object), the idea would be like breaking an existing flow into a sink and source.

So something like:

class Flow[-In, +Out, +Mat] {
.
.
.
def toSinkAndSource: (Sink[In],Source[Out]) = 
  Source
    .asSubscriber[In]
    .via(this)
    .toMat(Sink.asPublisher[Out](fanout = false))(Keep.both)
    .mapMaterializedValue {
      case (sub, pub) ⇒ (Sink.fromSubscriber(sub), Source.fromPublisher(pub))
    }.run()

Of course, you have to run it in order to actually get the sink and the source, so that might not be desirable.

@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Sep 18, 2018
@akka-ci
Copy link

akka-ci commented Sep 18, 2018

Test FAILed.

*
* Should be provided by Akka Streams, see https://github.com/akka/akka/issues/24853.
*/
def sinkToSource[M]: RunnableGraph[(Sink[M, NotUsed], Source[M, NotUsed])] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this method to Sink? It creates both a sink and source on materialization. I'd rather put it into RunnableGraph.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment
#25150 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RunnableGraph would perhaps make sense but it would be completely undiscoverable as there are no other factories (fromGraph is the only one) there.

*
* Should be provided by Akka Streams, see https://github.com/akka/akka/issues/24853.
*/
def sinkToSource[M]: RunnableGraph[(Sink[M, NotUsed], Source[M, NotUsed])] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M is typically used for the type of the materialized value. Please change to A or T.

@cedretaber
Copy link
Author

@hseeberger
Thank you for reviewing!
I am sorry it is so busy now, please wait for a couple of weeks to respond.

@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Jan 2, 2019
@akka-ci
Copy link

akka-ci commented Jan 2, 2019

Test FAILed.

@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Mar 28, 2019
@akka-ci
Copy link

akka-ci commented Mar 28, 2019

Test FAILed.

@cedretaber
Copy link
Author

I'm sorry, but in the present situation I do not have enough energy to discuss and promote this feature.
I apologize for the lack of my power and skills.

May I close this pull request?

I think that who have strong motivation for it should create the pull request again.

@patriknw
Copy link
Contributor

no problem, thanks for your efforts

@He-Pin
Copy link
Contributor

He-Pin commented Apr 29, 2022

@cedretaber Hi @cedretaber would you like to continue this PR?

@cedretaber
Copy link
Author

@hepin1989
At this moment, I have no intention to continue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-attention Indicates a PR validation failure (set by CI infrastructure)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants