Skip to content

Commit

Permalink
fix randomization problems by rearranging modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaeroxe committed May 14, 2023
1 parent 5292c11 commit d65d87a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion futures-macro/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream {

let shuffle = if random {
quote! {
__futures_crate::async_await::shuffle(&mut __select_arr);
__futures_crate::shuffle(&mut __select_arr);
}
} else {
quote!()
Expand Down
2 changes: 1 addition & 1 deletion futures-macro/src/stream_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(crate) fn stream_select(input: TokenStream) -> Result<TokenStream, syn::Erro
let mut any_pending = false;
{
let mut stream_array = [#(#field_idents.as_mut().map(|f| StreamEnum::#generic_idents(f)).unwrap_or(StreamEnum::None)),*];
__futures_crate::async_await::shuffle(&mut stream_array);
__futures_crate::shuffle(&mut stream_array);

for mut s in stream_array {
if let StreamEnum::None = s {
Expand Down
6 changes: 0 additions & 6 deletions futures-util/src/async_await/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ mod stream_select_mod;
#[cfg(feature = "async-await-macro")]
pub use self::stream_select_mod::*;

#[cfg(feature = "std")]
mod random;
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/64762
#[cfg(feature = "std")]
pub use self::random::*;

#[doc(hidden)]
#[inline(always)]
pub fn assert_unpin<T: Unpin>(_: &T) {}
Expand Down
4 changes: 3 additions & 1 deletion futures-util/src/future/select_ok.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ impl<Fut: TryFuture + Unpin> Future for SelectOk<Fut> {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let Self { inner } = &mut *self;
#[cfg(feature = "std")]
crate::shuffle(inner);
{
crate::shuffle(inner);
}
// loop until we've either exhausted all errors, a success was hit, or nothing is ready
loop {
let item = inner.iter_mut().enumerate().find_map(|(i, f)| match f.try_poll_unpin(cx) {
Expand Down
10 changes: 6 additions & 4 deletions futures-util/src/future/try_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ where
}

#[cfg(feature = "std")]
if crate::gen_index(2) == 0 {
poll_wrap!(a, b, Either::Left, Either::Right)
} else {
poll_wrap!(b, a, Either::Right, Either::Left)
{
if crate::gen_index(2) == 0 {
poll_wrap!(a, b, Either::Left, Either::Right)
} else {
poll_wrap!(b, a, Either::Right, Either::Left)
}
}

#[cfg(not(feature = "std"))]
Expand Down
6 changes: 6 additions & 0 deletions futures-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ mod async_await;
#[doc(hidden)]
pub use self::async_await::*;

#[cfg(feature = "std")]
mod random;
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/64762
#[cfg(feature = "std")]
pub use self::random::*;

// Not public API.
#[cfg(feature = "async-await")]
#[doc(hidden)]
Expand Down
File renamed without changes.

0 comments on commit d65d87a

Please sign in to comment.