@@ -51,43 +51,33 @@ trait MqttFlowSpec extends WordSpecLike with Matchers with BeforeAndAfterAll wit
5151
5252 val connection = Tcp ().outgoingConnection(" localhost" , 1883 )
5353
54- val mqttFlow : Flow [Command [Promise [ Done ]] , Either [MqttCodec .DecodeError , Event [Promise [ Done ] ]], NotUsed ] =
54+ val mqttFlow : Flow [Command [Nothing ] , Either [MqttCodec .DecodeError , Event [Nothing ]], NotUsed ] =
5555 Mqtt
5656 .clientSessionFlow(session, ByteString (" 1" ))
5757 .join(connection)
5858 // #create-streaming-flow
5959
6060 // #run-streaming-flow
61- val publishDone = Promise [Done ]
62- val (commands : SourceQueueWithComplete [Command [Promise [Done ]]], events : Future [Publish ]) =
61+ val (commands : SourceQueueWithComplete [Command [Nothing ]], events : Future [Publish ]) =
6362 Source
6463 .queue(2 , OverflowStrategy .fail)
6564 .via(mqttFlow)
66- .scan((Option .empty[Publish ], false )) {
67- case ((maybePublish, false ), Right (Event (_ : PubAck , carry))) =>
68- carry.foreach(_.success(Done ))
69- (maybePublish, true )
70- case ((None , publishAcked), Right (Event (p : Publish , _))) =>
71- (Some (p), publishAcked)
72- case ((maybePublish, publishAcked), _) =>
73- (maybePublish, publishAcked)
74- }
7565 .collect {
76- case ( Some (p : Publish ), true ) => p
66+ case Right ( Event (p : Publish , _) ) => p
7767 }
7868 .toMat(Sink .head)(Keep .both)
7969 .run()
8070
8171 commands.offer(Command (Connect (clientId, ConnectFlags .CleanSession )))
8272 commands.offer(Command (Subscribe (topic)))
83- session ! Command (
84- Publish (ControlPacketFlags .RETAIN | ControlPacketFlags .QoSAtLeastOnceDelivery , topic, ByteString (" ohi" )),
85- publishDone
86- )
73+ val publishDone = session ? Command (
74+ Publish (ControlPacketFlags .RETAIN | ControlPacketFlags .QoSAtLeastOnceDelivery , topic, ByteString (" ohi" )),
75+ Done
76+ )
8777
8878 // #run-streaming-flow
8979
90- publishDone.future. futureValue shouldBe Done
80+ publishDone.futureValue shouldBe Done
9181 events.futureValue match {
9282 case Publish (_, `topic`, _, bytes) => bytes shouldBe ByteString (" ohi" )
9383 case e => fail(" Unexpected event: " + e)
0 commit comments