feat(client): impl Sync for Client
Connector::connect already used &self, and so would require synchronization to be handled per connector anyway. Adding Sync to the Client allows users to setup config for a Client once, such as using a single connection Pool, and then making requests across multiple threads. Closes #254 BREAKING CHANGE: Connectors and Protocols passed to the `Client` must now also have a `Sync` bounds, but this shouldn't break default usage.
This commit is contained in:
@@ -144,12 +144,12 @@ impl NetworkConnector for MockConnector {
|
||||
///
|
||||
/// Otherwise, it behaves the same as `MockConnector`.
|
||||
pub struct ChannelMockConnector {
|
||||
calls: Sender<String>,
|
||||
calls: Mutex<Sender<String>>,
|
||||
}
|
||||
|
||||
impl ChannelMockConnector {
|
||||
pub fn new(calls: Sender<String>) -> ChannelMockConnector {
|
||||
ChannelMockConnector { calls: calls }
|
||||
ChannelMockConnector { calls: Mutex::new(calls) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,13 +158,13 @@ impl NetworkConnector for ChannelMockConnector {
|
||||
#[inline]
|
||||
fn connect(&self, _host: &str, _port: u16, _scheme: &str)
|
||||
-> ::Result<MockStream> {
|
||||
self.calls.send("connect".into()).unwrap();
|
||||
self.calls.lock().unwrap().send("connect".into()).unwrap();
|
||||
Ok(MockStream::new())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_ssl_verifier(&mut self, _verifier: ContextVerifier) {
|
||||
self.calls.send("set_ssl_verifier".into()).unwrap();
|
||||
self.calls.lock().unwrap().send("set_ssl_verifier".into()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user