@@ -8,7 +8,7 @@ use atomic::Atomic;
8
8
use event_listener_primitives:: HandlerId ;
9
9
use futures:: channel:: oneshot;
10
10
use futures:: future:: BoxFuture ;
11
- use futures:: stream:: FuturesUnordered ;
11
+ use futures:: stream:: { FuturesOrdered , FuturesUnordered } ;
12
12
use futures:: { select, FutureExt , StreamExt } ;
13
13
use lru:: LruCache ;
14
14
use parking_lot:: Mutex ;
@@ -68,6 +68,7 @@ struct Handlers {
68
68
pub ( super ) struct Farmer {
69
69
farm_fut : BoxFuture < ' static , anyhow:: Result < ( ) > > ,
70
70
piece_cache_worker_fut : BoxFuture < ' static , ( ) > ,
71
+ initial_plotting_states : Vec < PlottingState > ,
71
72
handlers : Arc < Handlers > ,
72
73
}
73
74
@@ -109,6 +110,10 @@ impl Farmer {
109
110
Ok ( ( ) )
110
111
}
111
112
113
+ pub ( super ) fn initial_plotting_states ( & self ) -> & [ PlottingState ] {
114
+ & self . initial_plotting_states
115
+ }
116
+
112
117
pub ( super ) fn on_plotting_state_change (
113
118
& self ,
114
119
callback : Handler2Fn < usize , PlottingState > ,
@@ -371,6 +376,21 @@ pub(super) async fn create_farmer(farmer_options: FarmerOptions) -> anyhow::Resu
371
376
} ) )
372
377
. detach ( ) ;
373
378
379
+ let initial_plotting_states = single_disk_farms
380
+ . iter ( )
381
+ . map ( |single_disk_farm| async {
382
+ if usize:: from ( single_disk_farm. total_sectors_count ( ) . await )
383
+ == single_disk_farm. plotted_sectors_count ( ) . await
384
+ {
385
+ PlottingState :: Idle
386
+ } else {
387
+ PlottingState :: Unknown
388
+ }
389
+ } )
390
+ . collect :: < FuturesOrdered < _ > > ( )
391
+ . collect ( )
392
+ . await ;
393
+
374
394
let mut single_disk_farms_stream = single_disk_farms
375
395
. into_iter ( )
376
396
. enumerate ( )
@@ -478,6 +498,7 @@ pub(super) async fn create_farmer(farmer_options: FarmerOptions) -> anyhow::Resu
478
498
anyhow:: Ok ( Farmer {
479
499
farm_fut,
480
500
piece_cache_worker_fut,
501
+ initial_plotting_states,
481
502
handlers,
482
503
} )
483
504
}
0 commit comments