Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify match and error #203

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading