添加个disconnect

This commit is contained in:
shenjack-5600u 2024-02-08 00:21:13 +08:00
parent 7108b337f9
commit 1cf098ccd8
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F

View File

@ -29,6 +29,7 @@ pub struct Cluster {
impl Cluster { impl Cluster {
pub async fn new(config: Config) -> Self { pub async fn new(config: Config) -> Self {
let disconnect = |reason: Payload, _: Client| { let disconnect = |reason: Payload, _: Client| {
async move { async move {
fatal!("socket disconnect: {:?}", reason); fatal!("socket disconnect: {:?}", reason);
@ -48,9 +49,14 @@ impl Cluster {
.connect() .connect()
.await .await
.expect("Failed to connect to center"); .expect("Failed to connect to center");
info!("websocket connected");
Self { config, ua, socket } Self { config, ua, socket }
} }
pub async fn disconnect(&self) {
self.socket.disconnect().await.expect("Failed to disconnect");
}
/// ```typescript /// ```typescript
/// this.ua = `openbmclapi-cluster/${version}` /// this.ua = `openbmclapi-cluster/${version}`
/// this.got = got.extend({ /// this.got = got.extend({
@ -164,5 +170,6 @@ mod tests {
let config = gen_config(); let config = gen_config();
let cluster = Cluster::new(config).await; let cluster = Cluster::new(config).await;
cluster.get_file_list().await.unwrap(); cluster.get_file_list().await.unwrap();
cluster.disconnect().await;
} }
} }