Pack to boxes outgoing connection handling
@@ -148,7 +148,8 @@ impl NetworkPart {
let outgoing_connections = outgoing_connections.clone();
match request {
NetworkRequest::SendMessage(peer, msg) => {
- let conn_tx = if let Some(conn_tx) = outgoing_connections.get(peer) {
+ let conn_tx =
+ if let Some(conn_tx) = outgoing_connections.get(peer) {
conn_tx
} else {
// Check limit
@@ -222,16 +223,17 @@ impl NetworkPart {
};
let send_handle = conn_tx.send(msg).map_err(log_error).map(drop);
- handle.spawn(send_handle);
+ tobox(send_handle)
}
NetworkRequest::DisconnectWithPeer(peer) => {
outgoing_connections.remove(&peer);
let event = NetworkEvent::PeerDisconnected(peer);
- handle.spawn(network_tx.clone().send(event).map(drop).map_err(log_error));
+ let fut = network_tx.clone().send(event).map(drop).map_err(log_error);
+ tobox(fut)
}
// Immediately stop the event loop.
NetworkRequest::Shutdown => {
- cancel_sender
+ let fut = cancel_sender
.take()
.ok_or_else(|| other_error("Shutdown twice"))
.and_then(|sender| {
@@ -239,11 +241,11 @@ impl NetworkPart {
|_| other_error("Can't send shutdown signal"),
)
})
- .map_err(log_error)?
+ .map_err(log_error)
+ .into_future();
+ tobox(fut)
}
}
-
- Ok(())
});
// Incoming connections limiter
@@ -308,7 +310,7 @@ impl NetworkPart {
})
.map_err(log_error);
- let cancel_handler = cancel_handler.map_err(|_| ());
+ let cancel_handler = cancel_handler.map_err(drop);
let tasks = vec![
tobox(server),
tobox(requests_handle),
