File tree Expand file tree Collapse file tree 1 file changed +13
-12
lines changed
Expand file tree Collapse file tree 1 file changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -148,13 +148,14 @@ impl Executor {
148148 }
149149
150150 pub fn poll_all_tasks ( & mut self ) {
151- let mut completed = Vec :: new ( ) ;
152-
153151 loop {
152+ // Drain any newly spawned tasks into our task list
154153 SPAWN_QUEUE . with ( |queue| {
155154 self . tasks . append ( & mut queue. borrow_mut ( ) ) ;
156155 } ) ;
157156
157+ // Poll all tasks, collecting completed ones
158+ let mut completed = Vec :: new ( ) ;
158159 let mut ctx = Context :: from_waker ( noop_waker_ref ( ) ) ;
159160
160161 for i in 0 ..self . tasks . len ( ) {
@@ -163,18 +164,18 @@ impl Executor {
163164 }
164165 }
165166
166- // tasks can spawn more tasks
167- let should_break = SPAWN_QUEUE . with ( |queue| {
168- let queue = queue. borrow ( ) ;
169- queue. is_empty ( )
170- } ) ;
171- if should_break {
172- break ;
167+ // Remove completed tasks immediately to prevent re-polling
168+ for idx in completed. into_iter ( ) . rev ( ) {
169+ let _ = self . tasks . remove ( idx) ;
173170 }
174- }
175171
176- for idx in completed. into_iter ( ) . rev ( ) {
177- let _ = self . tasks . remove ( idx) ;
172+ // Check if there are new tasks spawned during polling
173+ let has_new_tasks = SPAWN_QUEUE . with ( |queue| !queue. borrow ( ) . is_empty ( ) ) ;
174+
175+ // Continue if new tasks were spawned, otherwise we're done
176+ if !has_new_tasks {
177+ break ;
178+ }
178179 }
179180 }
180181}
You can’t perform that action at this time.
0 commit comments