Skip to content

Instantly share code, notes, and snippets.

@gfreezy
Created December 5, 2016 13:43
Show Gist options
  • Save gfreezy/25b03b2cc87f49ce4a49f62d299ffa07 to your computer and use it in GitHub Desktop.
Save gfreezy/25b03b2cc87f49ce4a49f62d299ffa07 to your computer and use it in GitHub Desktop.
impl ConnectionPool {
pub fn get_client<'a>(&'a self, addr: &str) -> Option<&'a rpc::Client> {
if let Some(&Ok(ref c)) = self.conns.get(addr) {
return Some(c);
}
let c = rpc::Client::new(addr);
self.conns.insert(addr.to_string(), c);
if let Some(&Ok(ref c)) = self.conns.get(addr) {
return Some(c);
}
None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment