From 520da02162ddb19fc49512f4858ff258846d8abf Mon Sep 17 00:00:00 2001 From: Patrick Auernig Date: Fri, 6 Apr 2018 13:29:01 +0200 Subject: [PATCH] Add unsubscribe command to client --- examples/discord_presence/src/main.rs | 3 +++ src/client.rs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/examples/discord_presence/src/main.rs b/examples/discord_presence/src/main.rs index 39c0c42..79a45db 100644 --- a/examples/discord_presence/src/main.rs +++ b/examples/discord_presence/src/main.rs @@ -36,5 +36,8 @@ fn main() { drpc.subscribe(Event::ActivityJoinRequest, |s| s) .expect("Failed to subscribe to event"); + drpc.unsubscribe(Event::ActivityJoinRequest, |j| j) + .expect("Failed to unsubscribe from event"); + loop { thread::sleep(time::Duration::from_secs(10)) }; } diff --git a/src/client.rs b/src/client.rs index 8552dd1..cea619c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -64,6 +64,12 @@ impl Client self.execute(Command::Subscribe, f(SubscriptionArgs::new()), Some(evt)) } + pub fn unsubscribe(&mut self, evt: Event, f: F) -> Result> + where F: FnOnce(SubscriptionArgs) -> SubscriptionArgs + { + self.execute(Command::Unsubscribe, f(SubscriptionArgs::new()), Some(evt)) + } + // private fn handshake(&mut self) -> Result<()> {