Skip to content

Commit

Permalink
improved use of select
Browse files Browse the repository at this point in the history
  • Loading branch information
randomairborne committed Nov 26, 2024
1 parent 4be4f1b commit cd99340
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 67 deletions.
106 changes: 58 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ tower-http = { version = "0.5", default-features = false, features = ["tracing",
axum = { version = "0.7", features = ["tokio", "http1", "http2", "query"], default-features = false }
tokio = { version = "1", features = ["rt-multi-thread", "macros", "signal"] }
tracing-subscriber = { version = "0.3", features = ["json"] }
futures-util = { version = "0.3", default-features = false }
tower-sombrero = { version = "0.0.4", features = ["axum"] }
askama = { version = "0.12", features = ["with-axum"] }
bustdir = { version = "0.1", features = ["askama"] }
tokio-util = { version = "0.7", features = ["rt"] }
serde = { version = "1", features = ["derive"] }
pyng = { path = "pyng" }
askama_escape = "0.10"
Expand All @@ -23,9 +25,9 @@ serde_json = "1"
thiserror = "1"
tracing = "0.1"
base64 = "0.22"
arc-swap = "1"
tower = "0.4"
vss = "0.1"
arc-swap = "1.7.1"

[workspace]
members = [
Expand Down
14 changes: 7 additions & 7 deletions src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;
use std::{pin::pin, time::Duration};

use futures_util::future::Either;
use pyng::{Bedrock, Java};
use tokio::select;

use crate::{
structures::{ChatStatus, MCPingResponse, PlayerSample, Players, Version},
Expand All @@ -14,11 +14,11 @@ pub async fn ping_java(address: String) -> Result<MCPingResponse, Failure> {
timeout: Some(Duration::from_secs(1)),
});
let sleep_future = tokio::time::sleep(Duration::from_secs(5));
#[allow(clippy::redundant_pub_crate)]
let (latency, response) = select! {
val = ping_future => val?,
() = sleep_future => return Err(Failure::TimedOut),
};
let (latency, response) =
match futures_util::future::select(pin!(ping_future), pin!(sleep_future)).await {
Either::Left(val) => val.0?,
Either::Right(_) => return Err(Failure::TimedOut),
};
let mut player_sample: Vec<PlayerSample> = Vec::new();
if let Some(sample) = response.players.sample {
for player in sample {
Expand Down
Loading

0 comments on commit cd99340

Please sign in to comment.