Spawned by this question: https://discuss.lightbend.com/t/create-source-from-sink-and-vice-versa/605
Maybe we should have a prepackaged thing for this?
Yeah seems like it may be useful and mind bending for beginners to make it yourself so good to provide it I think
/**
* Materializes into a sink connected to a source, i.e. the sink pushes into the source:
*
* +----------+ +----------+
* > Sink |------>| Source >
* +----------+ +----------+
*
* Should be provided by Akka Streams, see https://github.com/akka/akka/issues/24853.
*/
val connection: RunnableGraph[(Sink[String, NotUsed], Source[String, NotUsed])] =
Source
.asSubscriber[String]
.toMat(Sink.asPublisher[String](fanout = false))(Keep.both)
.mapMaterializedValue {
case (sub, pub) => (Sink.fromSubscriber(sub), Source.fromPublisher(pub))
}
Most helpful comment
Yeah seems like it may be useful and mind bending for beginners to make it yourself so good to provide it I think