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