Skip to content

Commit

Permalink
feat: add close method & implement drop
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeyax committed Jul 5, 2023
1 parent faf31c2 commit 49075b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
});

tokio::spawn(async move {
socket
.emit("discordUser", RpcClient::default().get_user())
.ok();
let rpc_client = RpcClient::default();
socket.emit("discordUser", rpc_client.get_user()).ok();
drop(rpc_client);
});
}
})
Expand Down
11 changes: 11 additions & 0 deletions src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,21 @@ impl RpcClient {
info!("client {}: get user", &self.client.get_client_id());
&self.user
}

pub fn close(&mut self) -> bool {
info!("client {}: close", &self.client.get_client_id());
self.client.disconnect().is_ok()
}
}

impl Default for RpcClient {
fn default() -> Self {
Self::new(DEFAULT_CLIENT_ID.into())
}
}

impl Drop for RpcClient {
fn drop(&mut self) {
self.close();
}
}

0 comments on commit 49075b0

Please sign in to comment.