@@ -14,7 +14,7 @@ use serde_json::Value;
1414use std:: error:: Error ;
1515use std:: fmt:: Debug ;
1616use std:: sync:: Arc ;
17- use std:: time:: Duration ;
17+ use std:: time:: { Duration , Instant } ;
1818use tokio:: io:: { ReadHalf , WriteHalf } ;
1919use tokio:: net:: TcpStream ;
2020use tokio:: sync:: broadcast:: { Receiver , Sender } ;
@@ -44,7 +44,7 @@ pub struct MoonrakerReply {
4444#[ derive( Debug , Clone ) ]
4545pub struct MoonrakerErrorReply
4646{
47- pub code : u32 ,
47+ pub code : i32 ,
4848 pub message : String ,
4949 pub id : u32 ,
5050}
@@ -234,7 +234,8 @@ impl MoonrakerConnection {
234234 . recv ( )
235235 . await
236236 . expect ( "Failed to retrieve internal event" ) ;
237-
237+
238+ let now = Instant :: now ( ) ;
238239 match & * event {
239240 WebsocketEvent :: MoonrakerReply ( reply) if reply. id == id => {
240241 let parsed_result: Result < T , serde_json:: Error > =
@@ -247,10 +248,17 @@ impl MoonrakerConnection {
247248 }
248249
249250 WebsocketEvent :: MoonrakerErrorReply ( error) if error. id == id => {
250- println ! ( "AAAAAAAAAAAAAAAAAAAAAA" ) ;
251251 return Err ( crate :: error:: Error :: MoonrakerErrorReply ( error. code , error. message . clone ( ) ) ) ;
252252 }
253- _ => continue , // TODO: This should eventually end
253+ _ => {
254+ if now. elapsed ( ) . as_secs ( ) > 20
255+ {
256+ return Err ( crate :: error:: Error :: Timeout ) ;
257+ }
258+ else {
259+ continue ;
260+ }
261+ } , // TODO: This should eventually end
254262 }
255263 }
256264 }
0 commit comments