Browse Source

Fixed up the ConnectionManager a tiny bit

main 0.3
Alex Feldman-Crough 2 weeks ago
parent
commit
7016c6d41c
  1. 2
      Cargo.toml
  2. 2
      README.md
  3. 15
      src/socket/pool.rs

2
Cargo.toml

@ -1,6 +1,6 @@
[package]
name = "tokio-zeromq"
version = "0.2.0"
version = "0.3.0"
authors = ["Alex Feldman-Crough <alex@fldcr.com>"]
edition = "2018"
license = "MPL-2.0"

2
README.md

@ -9,7 +9,7 @@ In your `Cargo.toml`, include `tokio-zeromq` as a dependency.
```toml
[dependencies.tokio-zeromq]
version = "0.2"
version = "0.3"
git = "https://git.fldcr.com/jafc/tokio-zeromq"
branch = "release"
```

15
src/socket/pool.rs

@ -6,18 +6,15 @@ use super::Socket;
use async_trait::async_trait;
pub struct ConnectionManager {
address: String,
context: zmq::Context,
socket_type: zmq::SocketType,
setup: Box<dyn Send + Sync + Fn(&zmq::Socket) -> zmq::Result<()>>,
}
impl ConnectionManager {
pub fn new<F>(context: zmq::Context, socket_type: zmq::SocketType, setup: F) -> Self
where
F: 'static + Send + Sync + Fn(&zmq::Socket) -> zmq::Result<()>,
{
let setup = Box::from(setup);
ConnectionManager { context, socket_type, setup }
pub fn new(context: zmq::Context, socket_type: zmq::SocketType, address: impl Into<String>) -> Self {
let address = address.into();
ConnectionManager { context, socket_type, address }
}
}
@ -27,8 +24,10 @@ impl bb8::ManageConnection for ConnectionManager {
type Error = Error;
async fn connect(&self) -> Result<Socket, Error> {
log::info!("Creating new {:?} socket", self.socket_type);
let skt = Socket::new(&self.context, self.socket_type)?;
(self.setup)(&skt)?;
log::info!("CONNECTing to {}", self.address);
skt.connect(&self.address)?;
Ok(skt)
}

Loading…
Cancel
Save