diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2019-10-13 18:33:57 +0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2019-10-13 18:33:57 +0800 |
commit | 114b385269c6f5049615e67c8c42dc25be337626 (patch) | |
tree | 111da08e84ae1dfa25c5781dee74eb764823e031 /cask/util | |
parent | f196a0b621a2afa45c577bd2641331152691b134 (diff) | |
download | cask-114b385269c6f5049615e67c8c42dc25be337626.tar.gz cask-114b385269c6f5049615e67c8c42dc25be337626.tar.bz2 cask-114b385269c6f5049615e67c8c42dc25be337626.zip |
fixes for WsClient
Diffstat (limited to 'cask/util')
-rw-r--r-- | cask/util/src/cask/util/WsClient.scala | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/cask/util/src/cask/util/WsClient.scala b/cask/util/src/cask/util/WsClient.scala index 152ab3b..6ba039e 100644 --- a/cask/util/src/cask/util/WsClient.scala +++ b/cask/util/src/cask/util/WsClient.scala @@ -27,7 +27,7 @@ object WsClient{ (f: PartialFunction[cask.util.Ws.Event, Unit]) (implicit ec: ExecutionContext, log: Logger): scala.concurrent.Future[WsClient] = { object receiveActor extends cask.util.BatchActor[Ws.Event] { - def run(items: Seq[Ws.Event]) = items.collect(f) + def run(items: Seq[Ws.Event]) = items.foreach(x => f.applyOrElse(x, (_: Ws.Event) => ())) } val p = Promise[WsClient] val impl = new WebsocketClientImpl(url) { @@ -41,10 +41,12 @@ object WsClient{ receiveActor.send(Ws.Binary(message)) } def onClose(code: Int, reason: String) = { - receiveActor.send(Ws.Close(code, reason)) + if (!p.isCompleted) p.failure(new Exception(s"WsClient failed: $code $reason")) + else receiveActor.send(Ws.Close(code, reason)) } def onError(ex: Exception): Unit = { - receiveActor.send(Ws.Error(ex)) + if (!p.isCompleted) p.failure(ex) + else receiveActor.send(Ws.Error(ex)) } } |