@@ -39,33 +39,30 @@ impl PriorityExecutor {
39
39
self . ex [ priority as usize ] . spawn ( future)
40
40
}
41
41
42
- /// Runs the executor until the future completes.
43
- async fn run < T > ( & self , future : impl Future < Output = T > ) -> T {
44
- future
45
- . or ( async {
46
- // Keep ticking inner executors forever.
47
- loop {
48
- let t0 = self . ex [ 0 ] . tick ( ) ;
49
- let t1 = self . ex [ 1 ] . tick ( ) ;
50
- let t2 = self . ex [ 2 ] . tick ( ) ;
42
+ /// Runs the executor forever.
43
+ async fn run ( & self ) {
44
+ loop {
45
+ for _ in 0 ..200 {
46
+ let t0 = self . ex [ 0 ] . tick ( ) ;
47
+ let t1 = self . ex [ 1 ] . tick ( ) ;
48
+ let t2 = self . ex [ 2 ] . tick ( ) ;
51
49
52
- // Wait until one of the ticks completes, trying them in order from highest
53
- // priority to lowest priority.
54
- t0. or ( t1) . or ( t2) . await ;
55
- }
56
- } )
57
- . await
50
+ // Wait until one of the ticks completes, trying them in order from highest
51
+ // priority to lowest priority.
52
+ t0. or ( t1) . or ( t2) . await ;
53
+ }
54
+
55
+ // Yield every now and then.
56
+ future:: yield_now ( ) . await ;
57
+ }
58
58
}
59
59
}
60
60
61
61
fn main ( ) {
62
62
static EX : PriorityExecutor = PriorityExecutor :: new ( ) ;
63
63
64
64
// Spawn a thread running the executor forever.
65
- thread:: spawn ( || {
66
- let forever = future:: pending :: < ( ) > ( ) ;
67
- future:: block_on ( EX . run ( forever) ) ;
68
- } ) ;
65
+ thread:: spawn ( || future:: block_on ( EX . run ( ) ) ) ;
69
66
70
67
let mut tasks = Vec :: new ( ) ;
71
68
0 commit comments