| 1363 | } |
| 1364 | |
| 1365 | pub async fn disconnect(self: &Arc<Self>) -> Result<()> { |
| 1366 | let self_ref = self.to_owned(); |
| 1367 | tokio::spawn(async move { |
| 1368 | let socket_io = self_ref.socket_io.lock().await; |
| 1369 | if let Some(socket_io) = &*socket_io { |
| 1370 | _ = socket_io.disconnect().await; |
| 1371 | } |
| 1372 | drop(socket_io); |
| 1373 | *self_ref.socket_io.lock().await = None; |
| 1374 | debug!("Connection closed!"); |
| 1375 | }) |
| 1376 | .await |
| 1377 | .pipe(|result| { |
| 1378 | return match result { |
| 1379 | Ok(_) => Ok(()), |
| 1380 | Err(e) if e.is_cancelled() => Ok(()), |
| 1381 | Err(e) => Err(Error::CommunicationError(format!( |
| 1382 | "Error while disconnecting: {}", |
| 1383 | e.to_string() |
| 1384 | ))), |
| 1385 | }; |
| 1386 | }) |
| 1387 | .log_error(std::module_path!(), |e| e.to_string())?; |
| 1388 | |
| 1389 | Ok(()) |
| 1390 | } |
| 1391 | |
| 1392 | pub async fn is_ready(self: &Arc<Self>) -> bool { |
| 1393 | self.is_ready.lock().await.is_ready() |