@@ -27,7 +27,7 @@ pub use openiap_proto::*;
2727pub use prost_types:: Timestamp ;
2828pub use protos:: flow_service_client:: FlowServiceClient ;
2929use sqids:: Sqids ;
30-
30+ use std :: fmt :: { Display , Formatter } ;
3131use tokio:: task:: JoinHandle ;
3232use tokio_tungstenite:: WebSocketStream ;
3333use tracing:: { debug, error, info, trace} ;
@@ -227,6 +227,17 @@ pub enum ClientState {
227227 /// The client is signed in and connected
228228 Signedin
229229}
230+ impl Display for ClientState {
231+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
232+ match self {
233+ ClientState :: Disconnected => write ! ( f, "Disconnected" ) ,
234+ ClientState :: Connecting => write ! ( f, "Connecting" ) ,
235+ ClientState :: Connected => write ! ( f, "Connected" ) ,
236+ ClientState :: Signedin => write ! ( f, "Signedin" ) ,
237+ }
238+ }
239+ }
240+
230241/// The `Config` struct provides the configuration for the OpenIAP service we are connecting to.
231242#[ derive( Debug , Clone , serde:: Deserialize ) ]
232243#[ allow( dead_code) ]
@@ -797,12 +808,14 @@ impl Client {
797808 }
798809 if state == ClientState :: Disconnected && !current. eq ( & state) {
799810 let me = self . clone ( ) ;
800- tokio:: task:: spawn ( async move {
801- let mut reply_queue_guard = me. rpc_reply_queue . lock ( ) . await ;
802- let mut callback_guard = me. rpc_callback . lock ( ) . await ;
803- * reply_queue_guard = None ;
804- * callback_guard = None ;
805- } ) ;
811+ if let Ok ( _handle) = tokio:: runtime:: Handle :: try_current ( ) {
812+ tokio:: task:: spawn ( async move {
813+ let mut reply_queue_guard = me. rpc_reply_queue . lock ( ) . await ;
814+ let mut callback_guard = me. rpc_callback . lock ( ) . await ;
815+ * reply_queue_guard = None ;
816+ * callback_guard = None ;
817+ } ) ;
818+ }
806819 }
807820 if state == ClientState :: Connecting && !current. eq ( & state) {
808821 if let Ok ( _handle) = tokio:: runtime:: Handle :: try_current ( ) {
@@ -811,14 +824,6 @@ impl Client {
811824 tokio:: task:: spawn ( async move {
812825 me. event_sender . send ( crate :: ClientEvent :: Connecting ) . await . unwrap ( ) ;
813826 } ) ;
814- // match tokio::task::Builder::new().name("setconnected-notify-connecting").spawn(async move {
815- // me.event_sender.send(crate::ClientEvent::Connecting).await.unwrap();
816- // }) {
817- // Ok(_) => (),
818- // Err(e) => {
819- // error!("Failed to spawn setconnected-notify-connecting task: {:?}", e);
820- // }
821- // }
822827 }
823828
824829 }
@@ -829,14 +834,6 @@ impl Client {
829834 tokio:: task:: spawn ( async move {
830835 me. event_sender . send ( crate :: ClientEvent :: Connected ) . await . unwrap ( ) ;
831836 } ) ;
832- // match tokio::task::Builder::new().name("setconnected-notify-connected").spawn(async move {
833- // me.event_sender.send(crate::ClientEvent::Connected).await.unwrap();
834- // }) {
835- // Ok(_) => (),
836- // Err(e) => {
837- // error!("Failed to spawn setconnected-notify-connected task: {:?}", e);
838- // }
839- // }
840837 }
841838 }
842839 if state == ClientState :: Signedin && current != ClientState :: Signedin {
@@ -845,14 +842,6 @@ impl Client {
845842 tokio:: task:: spawn ( async move {
846843 me. event_sender . send ( crate :: ClientEvent :: SignedIn ) . await . unwrap ( ) ;
847844 } ) ;
848- // match tokio::task::Builder::new().name("set_signedin-notify-connected").spawn(async move {
849- // me.event_sender.send(crate::ClientEvent::SignedIn).await.unwrap();
850- // }) {
851- // Ok(_) => (),
852- // Err(e) => {
853- // error!("Failed to spawn set_signedin-notify-connected task: {:?}", e);
854- // }
855- // };
856845 }
857846 }
858847 if state == ClientState :: Disconnected && !current. eq ( & state) {
@@ -867,26 +856,14 @@ impl Client {
867856 Some ( message) => message. to_string ( ) ,
868857 None => "" . to_string ( ) ,
869858 } ;
870- //if current != ClientState::Connecting {
871859 tokio:: task:: spawn ( async move {
872860 me. event_sender . send ( crate :: ClientEvent :: Disconnected ( message) ) . await . unwrap ( ) ;
873861 } ) ;
874- // match tokio::task::Builder::new().name("setconnected-notify-disconnected").spawn(async move {
875- // trace!("Disconnected: {}", message);
876- // me.event_sender.send(crate::ClientEvent::Disconnected(message)).await.unwrap();
877- // }) {
878- // Ok(_) => (),
879- // Err(e) => {
880- // error!("Failed to spawn setconnected-notify-disconnected task: {:?}", e);
881- // }
882- // }
883- //}
884862 }
885863
886864 self . kill_handles ( ) ;
887865 if let Ok ( _handle) = tokio:: runtime:: Handle :: try_current ( ) {
888866 let client = self . clone ( ) ;
889- // match tokio::task::Builder::new().name("kill_handles").spawn(async move {
890867 tokio:: task:: spawn ( async move {
891868 {
892869 let inner = client. inner . lock ( ) . await ;
@@ -941,12 +918,6 @@ impl Client {
941918 debug ! ( "Reconnecting disabled, stop now" ) ;
942919 }
943920 } ) ;
944- // {
945- // Ok(_) => (),
946- // Err(e) => {
947- // error!("Failed to spawn kill_handles task: {:?}", e);
948- // }
949- // }
950921 }
951922
952923 }
0 commit comments