Skip to content
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

Turn sinks into flows #27836

Open
johanandren opened this issue Oct 1, 2019 · 2 comments
Open

Turn sinks into flows #27836

johanandren opened this issue Oct 1, 2019 · 2 comments
Labels
discuss-design Design discussion would be good t:stream

Comments

@johanandren
Copy link
Member

Many of the sinks provides a materialized future value just to aggregate or signal a single value on completion. What if we made those sinks flows and passed the completion object downstream as an element instead.

source
  .via(FileIO.toPath("/tmp/example"))
  .runForeach(ioResult => 
     println(s"Writing done, wrote ${ioResult.bytes}")
  )

Good aspects

  • Can avoid the syntax overhead of having to deal with a materialized value/future/completion stage/execution context
  • Can perhaps avoid separate materialization where completion should trigger a new stream
  • Could allow those operators to be used in more places as they do not terminate the stream

Less good

  • Several options for doing the same thing is confusing
  • Kind of weird representing a single value arriving at some point as a stream when we have futures
@johanandren johanandren added t:stream discuss-design Design discussion would be good labels Oct 1, 2019
@patriknw
Copy link
Member

patriknw commented Oct 1, 2019

I think this idea originated from the recommendations for Alpakka connectors (cc @ennru) where you want to continue with the input elements, or the per element results, or the "commit token" after the connector. I didn't see it as a good option for aggregating sinks.

@ennru
Copy link
Member

ennru commented Oct 12, 2019

Flows are more useful than sinks, as even with sinks you often need to react on their materialized value. What users often end up with is running other flow in mapAsync so that the "inner" flow's result value continues downstream.

If we'd offer more of the current sinks in a flow-variant this hopping between flows and futures would not be needed.

I think Flow.fold and Sink.fold is a good example of this suggestion, where the sink is nothing but the flow with a Sink.head.

It might be harder to get the head around this kind of thinking, though. I guess we should collect more examples to see if it would be motivated to invest in this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss-design Design discussion would be good t:stream
Projects
None yet
Development

No branches or pull requests

3 participants