![](/img/trans.png)
[英]Akka-streams - How to take the materialized value of source which is flatMapConcatenated in to another source?
[英]Akka-streams - how to access the materialized value of the stream
我正在學習與Akka流一起工作,並且非常喜歡它,但物化部分對我來說仍然有些神秘。
...通過調用池客戶端流實現的HostConnectionPool實例上的shutdown()來觸發特定池的立即關閉
如何獲取HostConnectionPool實例?
更重要的是,我想了解一般如何訪問物化值並執行某些操作或從中檢索信息。
提前感謝任何文檔指針或解釋。
這是通過Source.viaMat
函數完成的。 從您的問題中提供的鏈接擴展代碼示例:
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()
由於Source.single
實現了Unit
, Keep.right
表示要保留poolClientFlow
實現的HostConnectionPool
。 在.toMat
函數中, Keep.both
表示要保留流池中的左池和來自Sink
的正確的Future
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.