close method

This commit is contained in:
Brandon Thomas committed 2021-09-26 20:11:04 -04:00
1 parent b6ec22e343
commit 94ea57deac
1 file changed
+12
+12
View File
@@ -167,6 +167,18 @@ impl TwitchWebsocketClient {
Ok(())
}
pub async fn close(&mut self) -> AnyhowResult<()> {
let mut socket = match self.socket {
None => return Ok(()), // Already closed.
Some(ref mut socket) => socket,
};
socket.close(None).await?;
self.socket = None;
Ok(())
}
pub fn is_connected(&self) -> bool {
// TODO: This probably isn't accurate
self.socket.is_some()