use async block instead of function for server connection
This commit is contained in:
parent
2634ae195d
commit
6e885a879b
1 changed files with 5 additions and 7 deletions
12
src/main.rs
12
src/main.rs
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue