Use async-await instead of combinators in main.rs
This commit is contained in:
parent
c2ebc19134
commit
936d12f4a0
24
src/main.rs
24
src/main.rs
|
@ -156,8 +156,8 @@ async fn main() -> Result<(), Error> {
|
||||||
|
|
||||||
// Once both are done, begin proxy duty
|
// Once both are done, begin proxy duty
|
||||||
let config = config.clone();
|
let config = config.clone();
|
||||||
let f = future::try_join(client, server)
|
tokio::spawn(async move {
|
||||||
.and_then(move |(client, server)| {
|
let (client, server) = future::try_join(client, server).await?;
|
||||||
let (client_sink, client_stream) = client.split();
|
let (client_sink, client_stream) = client.split();
|
||||||
let client_sink = client_sink.with(|m: ControlPacket<Clientbound>| {
|
let client_sink = client_sink.with(|m: ControlPacket<Clientbound>| {
|
||||||
let m = RawControlPacket::from(m);
|
let m = RawControlPacket::from(m);
|
||||||
|
@ -191,19 +191,15 @@ async fn main() -> Result<(), Error> {
|
||||||
client_stream,
|
client_stream,
|
||||||
server_sink,
|
server_sink,
|
||||||
server_stream,
|
server_stream,
|
||||||
)
|
).await?;
|
||||||
})
|
|
||||||
.or_else(move |err| {
|
println!("Client connection closed: {}", addr);
|
||||||
future::ready({
|
|
||||||
if err.is_connection_closed() {
|
Ok::<_, Error>(())
|
||||||
Ok(())
|
}.unwrap_or_else(move |err| {
|
||||||
} else {
|
if !err.is_connection_closed() {
|
||||||
println!("Error on connection {}: {:?}", addr, err);
|
println!("Error on connection {}: {:?}", addr, err);
|
||||||
Err(())
|
|
||||||
}
|
}
|
||||||
})
|
}));
|
||||||
})
|
|
||||||
.map_ok(move |()| println!("Client connection closed: {}", addr));
|
|
||||||
tokio::spawn(f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue