Added the ability to disconnect from the server
This commit is contained in:
parent
01da5afb46
commit
8f100c0f1c
|
|
@ -101,8 +101,7 @@ impl<Out> Client<Out>
|
|||
let _ = self.out_channel
|
||||
.send(ClientMessage::Disconnect {
|
||||
id: self.details.uuid,
|
||||
connection: self.connection.clone()}.into()
|
||||
);
|
||||
}.into()).await;
|
||||
}
|
||||
|
||||
async fn error(&self, msg: &str) {
|
||||
|
|
@ -139,16 +138,11 @@ impl<Out> Drop for Client<Out>
|
|||
{
|
||||
fn drop(&mut self) {
|
||||
let connection = self.connection.clone();
|
||||
let out = self.out_channel.clone();
|
||||
|
||||
let id = self.details.uuid.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let _ = connection.write(Disconnected).await;
|
||||
let _ = out.send(
|
||||
ClientMessage::Disconnect {
|
||||
id,
|
||||
connection
|
||||
}.into()).await;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ pub enum ClientMgrMessage {
|
|||
|
||||
impl From<ClientMessage> for ClientMgrMessage {
|
||||
fn from(msg: ClientMessage) -> Self {
|
||||
use ClientMessage::{IncomingMessage,IncomingGlobalMessage};
|
||||
use ClientMessage::{IncomingMessage,IncomingGlobalMessage,Disconnect};
|
||||
|
||||
match msg {
|
||||
IncomingMessage {
|
||||
|
|
@ -56,6 +56,7 @@ impl From<ClientMessage> for ClientMgrMessage {
|
|||
from,
|
||||
content
|
||||
},
|
||||
Disconnect {id} => ClientMgrMessage::Remove {id},
|
||||
_ => unimplemented!()
|
||||
}
|
||||
|
||||
|
|
@ -155,6 +156,9 @@ impl<Out> ClientManager<Out>
|
|||
});
|
||||
join_all(futures).await;
|
||||
},
|
||||
Some(Remove {id}) => {
|
||||
self.clients.lock().await.remove(&id);
|
||||
}
|
||||
_ => {
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ pub enum ClientMessage {
|
|||
#[allow(dead_code)]
|
||||
RequestedUpdate { from: Uuid },
|
||||
|
||||
Disconnect { id: Uuid, connection: Arc<Connection> },
|
||||
Disconnect { id: Uuid },
|
||||
|
||||
Error,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue