Skip to content

Commit d206459

Browse files
committed
Early-out in Runner when the queue is empty.
1 parent 63e0a93 commit d206459

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/local_executor.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,19 @@ impl State {
431431
}
432432

433433
pub async fn run<T>(&self, future: impl Future<Output = T>) -> T {
434-
let mut ticker = Ticker::new(self);
435-
436434
// A future that runs tasks forever.
437435
let run_forever = async {
438436
loop {
439437
for _ in 0..200 {
440-
ticker.runnable().await.run();
438+
// SAFETY: All UnsafeCell accesses to queue are tightly scoped, and because
439+
// `LocalExecutor` is !Send, there is no way to have concurrent access to the
440+
// values in `State`, including the queue field.
441+
match unsafe { &mut *self.queue.get() }.pop_back() {
442+
Some(runnable) => {
443+
runnable.run();
444+
},
445+
None => break,
446+
}
441447
}
442448
future::yield_now().await;
443449
}

0 commit comments

Comments
 (0)