mirror of
https://github.com/lune-org/mlua-luau-scheduler.git
synced 2025-04-10 21:40:55 +01:00
Fix rare early exit condition because of async race
This commit is contained in:
parent
13d1f13c88
commit
78bb958797
1 changed files with 10 additions and 11 deletions
|
@ -3,7 +3,7 @@ use std::{collections::VecDeque, rc::Rc};
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use smol::{
|
use smol::{
|
||||||
channel::{Receiver, Sender},
|
channel::{Receiver, Sender},
|
||||||
future::{race, yield_now},
|
future::{yield_now, FutureExt},
|
||||||
lock::Mutex,
|
lock::Mutex,
|
||||||
stream::StreamExt,
|
stream::StreamExt,
|
||||||
*,
|
*,
|
||||||
|
@ -127,17 +127,16 @@ impl ThreadRuntime {
|
||||||
// executor forward, until all lua threads finish
|
// executor forward, until all lua threads finish
|
||||||
let fut = async {
|
let fut = async {
|
||||||
loop {
|
loop {
|
||||||
race(
|
// Wait for a new thread to arrive __or__ next futures step, prioritizing
|
||||||
// Wait for next futures step...
|
// new threads, so we don't accidentally exit when there is more work to do
|
||||||
async {
|
self.rx
|
||||||
|
.recv()
|
||||||
|
.or(async {
|
||||||
lua_exec.tick().await;
|
lua_exec.tick().await;
|
||||||
},
|
Ok(())
|
||||||
// ...or for a new thread to arrive
|
})
|
||||||
async {
|
.await
|
||||||
self.rx.recv().await.ok();
|
.ok();
|
||||||
},
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// If a new thread was spawned onto queue, we
|
// If a new thread was spawned onto queue, we
|
||||||
// must drain it and schedule on the executor
|
// must drain it and schedule on the executor
|
||||||
|
|
Loading…
Add table
Reference in a new issue