diff options
Diffstat (limited to 'lampada/src')
-rw-r--r-- | lampada/src/error.rs | 6 | ||||
-rw-r--r-- | lampada/src/lib.rs | 13 |
2 files changed, 13 insertions, 6 deletions
diff --git a/lampada/src/error.rs b/lampada/src/error.rs index 40be012..f29d0cc 100644 --- a/lampada/src/error.rs +++ b/lampada/src/error.rs @@ -1,10 +1,10 @@ use std::sync::Arc; -#[cfg(not(target_arch = "wasm32"))] -use ::tokio::time::error::Elapsed; use stanza::client::Stanza; use thiserror::Error; use tokio::sync::{mpsc::error::SendError, oneshot::error::RecvError}; +#[cfg(not(target_arch = "wasm32"))] +use tokio::time::error::Elapsed; #[cfg(target_arch = "wasm32")] use tokio::time::Elapsed; #[cfg(target_arch = "wasm32")] @@ -28,6 +28,7 @@ pub enum ConnectionError { } #[derive(Debug, Error, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub enum CommandError<T> { #[error("actor: {0}")] Actor(ActorError), @@ -61,6 +62,7 @@ pub enum ReadError { } #[derive(Debug, Error, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub enum ActorError { #[error("receive timed out")] Timeout, diff --git a/lampada/src/lib.rs b/lampada/src/lib.rs index dacc56d..5b1f89f 100644 --- a/lampada/src/lib.rs +++ b/lampada/src/lib.rs @@ -217,9 +217,10 @@ where else => break, }; match msg { - CoreClientCommand::Connect => { + CoreClientCommand::Connect(sender) => { match self.connected { Some(_) => { + sender.send(Err(ConnectionError::AlreadyConnected)); self.logic .clone() .handle_connection_error(ConnectionError::AlreadyConnected) @@ -238,9 +239,10 @@ where self.logic .clone() .handle_connection_error(ConnectionError::InvalidServerJID( - e, + e.clone(), )) .await; + sender.send(Err(ConnectionError::InvalidServerJID(e))); continue; } }; @@ -269,15 +271,18 @@ where self.logic.clone().handle_connect(connected.clone()).await; self.connected = Some((connected, supervisor)); + // REMEMBER TO NOTIFY IT@S GOOD + sender.send(Ok(())); } Err(e) => { tracing::error!("error: {}", e); self.logic .clone() .handle_connection_error(ConnectionError::ConnectionFailed( - e.into(), + e.clone().into(), )) .await; + sender.send(Err(ConnectionError::ConnectionFailed(e))); } } } @@ -315,7 +320,7 @@ where pub enum CoreClientCommand<C> { // TODO: login invisible xep-0186 /// connect to XMPP chat server. gets roster and publishes initial presence. - Connect, + Connect(oneshot::Sender<Result<(), ConnectionError>>), /// disconnect from XMPP chat server, sending unavailable presence then closing stream. Disconnect, /// TODO: generics |