Use async-await instead of combinators in main.rs

This commit is contained in:
Jonas Herzig 2020-04-05 18:46:03 +02:00
parent c2ebc19134
commit 936d12f4a0

View file

@ -156,8 +156,8 @@ async fn main() -> Result<(), Error> {
// Once both are done, begin proxy duty
let config = config.clone();
let f = future::try_join(client, server)
.and_then(move |(client, server)| {
tokio::spawn(async move {
let (client, server) = future::try_join(client, server).await?;
let (client_sink, client_stream) = client.split();
let client_sink = client_sink.with(|m: ControlPacket<Clientbound>| {
let m = RawControlPacket::from(m);
@ -191,19 +191,15 @@ async fn main() -> Result<(), Error> {
client_stream,
server_sink,
server_stream,
)
})
.or_else(move |err| {
future::ready({
if err.is_connection_closed() {
Ok(())
} else {
).await?;
println!("Client connection closed: {}", addr);
Ok::<_, Error>(())
}.unwrap_or_else(move |err| {
if !err.is_connection_closed() {
println!("Error on connection {}: {:?}", addr, err);
Err(())
}
})
})
.map_ok(move |()| println!("Client connection closed: {}", addr));
tokio::spawn(f);
}));
}
}