Does composite flow make loop?
我想了解以下代码片段的工作原理:
1
2 |
val flow: Flow[Message, Message, Future[Done]] =
Flow.fromSinkAndSourceMat(printSink, helloSource)(Keep.left) |
两个人在这个线程上给出了非常精彩的解释。我了解复合流的概念,但它是如何在 websocket 客户端上工作的。
考虑以下代码:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import akka.actor.ActorSystem
import akka.{ Done, NotUsed } import akka.http.scaladsl.Http import akka.stream.ActorMaterializer import akka.stream.scaladsl._ import akka.http.scaladsl.model._ import akka.http.scaladsl.model.ws._ import scala.concurrent.Future object SingleWebSocketRequest { // print each incoming strict text message val helloSource: Source[Message, NotUsed] = // the Future[Done] is the materialized value of Sink.foreach // upgradeResponse is a Future[WebSocketUpgradeResponse] that val connected = upgradeResponse.map { upgrade => // in a real application you would not side effect here |
它是一个websocket客户端,向websocket服务器发送消息,printSink接收并打印出来。
怎么可能,printSink收到消息,Sink和Source之间没有连接。
它像一个循环吗?
来源:https://www.codenong.com/55703607/