From 3c2c39b8b1bf492ec6d2327630c11eb8e71040b3 Mon Sep 17 00:00:00 2001 From: Austin Hellyer Date: Thu, 10 Nov 2016 07:32:40 -0800 Subject: Properly shutdown on connection Drop --- src/client/connection.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/client') diff --git a/src/client/connection.rs b/src/client/connection.rs index fd06160..1ba3341 100644 --- a/src/client/connection.rs +++ b/src/client/connection.rs @@ -456,6 +456,30 @@ impl Connection { } } +impl Drop for Connection { + fn drop(&mut self) { + match self.shutdown() { + Ok(()) => { + if let Some([shard, shards]) = self.shard_info { + println!("Correctly shutdown shard {}/{}", shard, shards - 1); + } else { + println!("Correctly shutdown connection"); + } + }, + Err(why) => { + if let Some([shard, shards]) = self.shard_info { + println!("Failed to shutdown shard {}/{}: {:?}", + shard, + shards - 1, + why); + } else { + println!("Failed to shutdown connection: {:?}", why); + } + } + } + } +} + trait ReceiverExt { fn recv_json(&mut self, decode: F) -> Result where F: FnOnce(Value) -> Result; -- cgit v1.2.3