Skip to content

Commit

Permalink
Merge pull request #203 from zeromq/simplify-match-and-error
Browse files Browse the repository at this point in the history
Simplify match and error
  • Loading branch information
rgbkrk authored Dec 13, 2024
2 parents 77f842b + 98f9217 commit d06811a
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,16 @@ pub trait Socket: Sized + Send {
let endpoint = TryIntoEndpoint::try_into(endpoint)?;

let cloned_backend = self.backend();
let cback = move |result| {
let cback = move |result: ZmqResult<(FramedIo, Endpoint)>| {
let cloned_backend = cloned_backend.clone();
async move {
let result = match result {
Ok((socket, endpoint)) => {
match util::peer_connected(socket, cloned_backend.clone()).await {
Ok(peer_id) => Ok((endpoint, peer_id)),
Err(e) => Err(e),
}
}
Ok((socket, endpoint)) => util::peer_connected(socket, cloned_backend.clone())
.await
.map(|peer_id| (endpoint, peer_id)),
Err(e) => Err(e),
};

match result {
Ok((endpoint, peer_id)) => {
if let Some(monitor) = cloned_backend.monitor().lock().as_mut() {
Expand Down Expand Up @@ -303,22 +301,13 @@ pub trait Socket: Sized + Send {
let backend = self.backend();
let endpoint = TryIntoEndpoint::try_into(endpoint)?;

let result = match util::connect_forever(endpoint).await {
Ok((socket, endpoint)) => match util::peer_connected(socket, backend).await {
Ok(peer_id) => Ok((endpoint, peer_id)),
Err(e) => Err(e),
},
Err(e) => Err(e),
};
match result {
Ok((endpoint, peer_id)) => {
if let Some(monitor) = self.backend().monitor().lock().as_mut() {
let _ = monitor.try_send(SocketEvent::Connected(endpoint, peer_id));
}
Ok(())
}
Err(e) => Err(e),
let (socket, endpoint) = util::connect_forever(endpoint).await?;
let peer_id = util::peer_connected(socket, backend).await?;

if let Some(monitor) = self.backend().monitor().lock().as_mut() {
let _ = monitor.try_send(SocketEvent::Connected(endpoint, peer_id));
}
Ok(())
}

/// Creates and setups new socket monitor
Expand Down

0 comments on commit d06811a

Please sign in to comment.