Disconnects from server, if connected. Returns Err(ButtplugClientError) if disconnection fails. It can be assumed that even on failure, the client will be disconnected.
(&self)
| 388 | /// Returns Err(ButtplugClientError) if disconnection fails. It can be assumed |
| 389 | /// that even on failure, the client will be disconnected. |
| 390 | pub fn disconnect(&self) -> ButtplugClientResultFuture { |
| 391 | if !self.connected() { |
| 392 | return future::ready(Err(ButtplugConnectorError::ConnectorNotConnected.into())).boxed(); |
| 393 | } |
| 394 | // Send the connector to the internal loop for management. Once we throw |
| 395 | // the connector over, the internal loop will handle connecting and any |
| 396 | // further communications with the server, if connection is successful. |
| 397 | let (tx, rx) = oneshot::channel(); |
| 398 | let msg = ButtplugClientRequest::Disconnect(tx); |
| 399 | let send_fut = self.message_sender.send_message_to_event_loop(msg); |
| 400 | let connected = self.connected.clone(); |
| 401 | async move { |
| 402 | connected.store(false, Ordering::Relaxed); |
| 403 | send_fut.await?; |
| 404 | // Wait for disconnect to complete, but don't fail if channel closed |
| 405 | let _ = rx.await; |
| 406 | Ok(()) |
| 407 | } |
| 408 | .boxed() |
| 409 | } |
| 410 | |
| 411 | /// Tells server to start scanning for devices. |
| 412 | /// |
no test coverage detected