如何將源轉換為流?
輸入:Source[ByteString,NotUsed] 中間步驟:呼叫回傳 InputStream 的 API 輸出:Flow[ByteString,ByteString,NotUsed]
我這樣做是:輸入型別是 = Source[ByteString,NotUsed]
val sink: Sink[ByteString,InputStream] = StreamConverters.asInputStream()
val output: InputStream = <API CALL>
val mySource: Source[ByteString,Future[IOResult]] = StreamConverters.fromInputStream(() => output)
val myFlow: Flow[ByteString,ByteString,NotUsed] = Flow.fromSinkAndSource(sink,source)
當我在源中使用上述 Flow 時,它回傳一個空結果。有人可以幫我弄清楚我做得對嗎?
uj5u.com熱心網友回復:
我不確定您是否完全掌握您想要實作的目標,但也許這是一個用例flatMapConcat:
def readInputstream(bs: ByteString): Source[ByteString, Future[IOResult]] =
// Get some IS from the ByteString
StreamConverters.fromInputStream(() => ???)
val myFlow: Flow[ByteString, ByteString, NotUsed] =
Flow.flatMapConcat(bs => readInputstream(bs))
// And use it like this:
val source: Source[ByteString] = ???
source
.via(myFlow)
.to(???)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/524176.html
標籤:斯卡拉阿卡流
下一篇:我想禁止使用已棄用的API
