Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiny plotting simplification #3171

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions crates/subspace-farmer/src/single_disk_farm/plotting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use futures::stream::FuturesOrdered;
use futures::{select, FutureExt, SinkExt, StreamExt};
use parity_scale_codec::Encode;
use std::collections::HashSet;
use std::future::{pending, Future};
use std::future::Future;
use std::io;
use std::num::NonZeroUsize;
use std::ops::Range;
Expand Down Expand Up @@ -167,7 +167,7 @@ where
);
break;
}
maybe_sector_plotting_result = maybe_wait_futures_ordered(&mut sectors_being_plotted).fuse() => {
maybe_sector_plotting_result = sectors_being_plotted.select_next_some() => {
process_plotting_result(
maybe_sector_plotting_result?,
sectors_metadata,
Expand All @@ -179,7 +179,7 @@ where
}
}
}
maybe_sector_plotting_result = maybe_wait_futures_ordered(&mut sectors_being_plotted).fuse() => {
maybe_sector_plotting_result = sectors_being_plotted.select_next_some() => {
process_plotting_result(
maybe_sector_plotting_result?,
sectors_metadata,
Expand Down Expand Up @@ -244,19 +244,6 @@ async fn process_plotting_result(
Ok(())
}

/// Wait for next element in `FuturesOrdered`, but only if it is not empty. This avoids calling
/// `.poll_next()` if `FuturesOrdered` is already empty, so it can be reused indefinitely
async fn maybe_wait_futures_ordered<F>(stream: &mut FuturesOrdered<F>) -> F::Output
where
F: Future,
{
if stream.is_empty() {
pending().await
} else {
stream.next().await.expect("Not empty; qed")
}
}

enum PlotSingleSectorResult<F> {
Scheduled(F),
Skipped,
Expand Down
Loading