From ea7ec251c0f5e43ca7d1be284caad13750ad2600 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Fri, 25 Oct 2024 15:42:12 +0300 Subject: [PATCH] Tiny plotting simplification --- .../src/single_disk_farm/plotting.rs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/crates/subspace-farmer/src/single_disk_farm/plotting.rs b/crates/subspace-farmer/src/single_disk_farm/plotting.rs index cd97c295a3..1c5d105cf5 100644 --- a/crates/subspace-farmer/src/single_disk_farm/plotting.rs +++ b/crates/subspace-farmer/src/single_disk_farm/plotting.rs @@ -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; @@ -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, @@ -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, @@ -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(stream: &mut FuturesOrdered) -> F::Output -where - F: Future, -{ - if stream.is_empty() { - pending().await - } else { - stream.next().await.expect("Not empty; qed") - } -} - enum PlotSingleSectorResult { Scheduled(F), Skipped,