Skip to content

Commit

Permalink
respect the required rt feature
Browse files Browse the repository at this point in the history
  • Loading branch information
maminrayej committed Jan 18, 2025
1 parent 762526e commit 5dcdb5e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tokio/src/macros/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ doc! {macro_rules! select {

// Return `Pending` when the task budget is depleted since budget-aware futures
// are going to yield anyway and other futures will not cooperate.
::std::task::ready!($crate::task::poll_budget_available(cx));
::std::task::ready!($crate::macros::support::poll_budget_available(cx));

for i in 0..BRANCHES {
let branch;
Expand Down
7 changes: 7 additions & 0 deletions tokio/src/macros/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ cfg_macros! {
pub fn thread_rng_n(n: u32) -> u32 {
crate::runtime::context::thread_rng_n(n)
}

pub fn poll_budget_available(cx: &mut std::task::Context<'_>) -> std::task::Poll<()> {
#[cfg(feature = "rt")]
{ crate::task::poll_budget_available(cx) }
#[cfg(not(feature = "rt"))]
{ std::task::Poll::Ready(()) }
}
}

pub use std::future::{Future, IntoFuture};
Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/macros_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ async fn mut_ref_patterns() {
};
}

#[maybe_tokio_test]
#[tokio::test]
async fn select_is_budget_aware() {
const BUDGET: usize = 128;

Expand Down

0 comments on commit 5dcdb5e

Please sign in to comment.