use async block instead of function for server connection

This commit is contained in:
LordMZTE 2020-09-25 19:52:57 +02:00
parent 2634ae195d
commit 6e885a879b

View file

@ -11,7 +11,7 @@ use tokio::time;
use anyhow::{Context, Result};
use asciify::AsciiBuilder;
use async_minecraft_ping::{ConnectionConfig, StatusResponse};
use async_minecraft_ping::ConnectionConfig;
use clap::App;
use image::ImageFormat;
use itertools::Itertools;
@ -65,7 +65,10 @@ async fn main() -> Result<()> {
let response = tokio::select! {
_ = &mut timeout => Err(anyhow!("Connection to server timed out")),
r = ping_server(config) => r,
r = async {
let mut con = config.connect().await?;
con.status().await
} => r,
}?;
//endregion
@ -141,8 +144,3 @@ async fn get_image(favicon: String, config: AsciiConfig) -> Result<Vec<u8>> {
buf.reset()?;
Ok(buf.as_slice().to_vec())
}
async fn ping_server(server: ConnectionConfig) -> Result<StatusResponse> {
let mut con = server.connect().await?;
con.status().await
}