Skip to content

Commit

Permalink
test fix for infinite yielding
Browse files Browse the repository at this point in the history
  • Loading branch information
bjcscat committed Oct 3, 2024
1 parent 6d4d2df commit 25b4922
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/mlua-luau-scheduler/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
thread::panicking,
};

use futures_lite::prelude::*;
use futures_lite::{future::yield_now, prelude::*};
use mlua::prelude::*;

use async_executor::{Executor, LocalExecutor};
Expand Down Expand Up @@ -373,7 +373,16 @@ impl<'lua> Scheduler<'lua> {
.race(fut_spawn)
.race(fut_defer)
.race(fut_futs)
.race(local_exec.tick()),
.race(
async {
yield_now().await;

while !local_exec.is_empty() {
yield_now().await;
}
}
.or(local_exec.tick()),
),
)
.await;

Expand Down Expand Up @@ -417,7 +426,6 @@ impl<'lua> Scheduler<'lua> {

trace!(
futures_spawned = num_futures,
// futures_processed = num_processed,
lua_threads_spawned = num_spawned,
lua_threads_deferred = num_deferred,
"loop"
Expand Down

0 comments on commit 25b4922

Please sign in to comment.