22
33use crate :: plotter:: { Plotter , SectorPlottingProgress } ;
44use async_trait:: async_trait;
5+ use event_listener:: Event ;
56use futures:: channel:: mpsc;
7+ use futures:: future;
68use std:: any:: type_name_of_val;
9+ use std:: pin:: pin;
710use std:: time:: Duration ;
811use subspace_core_primitives:: sectors:: SectorIndex ;
912use subspace_core_primitives:: PublicKey ;
@@ -18,6 +21,7 @@ use tracing::{error, trace};
1821pub struct PoolPlotter {
1922 plotters : Vec < Box < dyn Plotter + Send + Sync > > ,
2023 retry_interval : Duration ,
24+ notification : Event ,
2125}
2226
2327#[ async_trait]
@@ -66,6 +70,7 @@ impl Plotter for PoolPlotter {
6670 )
6771 . await
6872 {
73+ self . notification . notify_relaxed ( 1 ) ;
6974 return ;
7075 }
7176 }
@@ -74,7 +79,11 @@ impl Plotter for PoolPlotter {
7479 retry_interval = ?self . retry_interval,
7580 "All plotters are busy, will wait and try again later"
7681 ) ;
77- tokio:: time:: sleep ( self . retry_interval ) . await ;
82+ future:: select (
83+ pin ! ( tokio:: time:: sleep( self . retry_interval) ) ,
84+ self . notification . listen ( ) ,
85+ )
86+ . await ;
7887 }
7988 }
8089
@@ -99,6 +108,7 @@ impl Plotter for PoolPlotter {
99108 )
100109 . await
101110 {
111+ self . notification . notify_relaxed ( 1 ) ;
102112 return true ;
103113 }
104114 }
@@ -113,6 +123,7 @@ impl PoolPlotter {
113123 Self {
114124 plotters,
115125 retry_interval,
126+ notification : Event :: new ( ) ,
116127 }
117128 }
118129}
0 commit comments