This is done using a function Source.viaMat. Extending the sample code from the link in your question:
import akka.http.scaladsl.Http.HostConnectionPool
import akka.stream.scaladsl.Keep
import akka.stream.scaladsl.RunnableGraph
val poolClientFlow = Http().cachedHostConnectionPool[Int]("akka.io")
val graph: RunnableGraph[(HostConnectionPool, Future[(Try[HttpResponse], Int)])] =
Source.single(HttpRequest(uri = "/") -> 42)
.viaMat(poolClientFlow)(Keep.right)
.toMat(Sink.head)(Keep.both)
val (pool, fut) = graph.run()
pool.shutdown()
Since it Source.singlematerializes in Unit, it Keep.rightsays that it saves HostConnectionPoolinto which it enters poolClientFlow. The .toMatfunction Keep.bothsays to save both the left pool from the stream and the right Futurefrom Sink.
source
share