mirror of
https://github.com/lune-org/mlua-luau-scheduler.git
synced 2025-04-16 01:43:55 +01:00
Get rid of unwraps where possible
This commit is contained in:
parent
cd090d877f
commit
13d1f13c88
1 changed files with 9 additions and 10 deletions
|
@ -74,18 +74,15 @@ impl ThreadRuntime {
|
||||||
lua.globals().set("spawn", fn_spawn)?;
|
lua.globals().set("spawn", fn_spawn)?;
|
||||||
lua.globals().set("defer", fn_defer)?;
|
lua.globals().set("defer", fn_defer)?;
|
||||||
|
|
||||||
// HACK: Extract mlua "pending" constant value
|
// HACK: Extract mlua "pending" constant value and store it
|
||||||
let pending = lua
|
let pending = lua
|
||||||
.create_async_function(|_, ()| async move {
|
.create_async_function(|_, ()| async move {
|
||||||
yield_now().await;
|
yield_now().await;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})?
|
||||||
.unwrap()
|
.into_lua_thread(lua)?
|
||||||
.into_lua_thread(lua)
|
.resume::<_, LuaValue>(())?;
|
||||||
.unwrap()
|
let pending_key = lua.create_registry_value(pending)?;
|
||||||
.resume::<_, LuaValue>(())
|
|
||||||
.unwrap();
|
|
||||||
let pending_key = lua.create_registry_value(pending).unwrap();
|
|
||||||
|
|
||||||
Ok(ThreadRuntime {
|
Ok(ThreadRuntime {
|
||||||
pending_key,
|
pending_key,
|
||||||
|
@ -112,7 +109,7 @@ impl ThreadRuntime {
|
||||||
let stored = ThreadWithArgs::new(lua, thread, args);
|
let stored = ThreadWithArgs::new(lua, thread, args);
|
||||||
|
|
||||||
self.queue.lock_blocking().push_front(stored);
|
self.queue.lock_blocking().push_front(stored);
|
||||||
self.tx.try_send(()).unwrap();
|
self.tx.try_send(()).unwrap(); // Unwrap is safe since this struct also holds the receiver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,7 +146,9 @@ impl ThreadRuntime {
|
||||||
// before we got here, so we need to check it again
|
// before we got here, so we need to check it again
|
||||||
let (thread, args) = queued_thread.into_inner(lua);
|
let (thread, args) = queued_thread.into_inner(lua);
|
||||||
if thread.status() == LuaThreadStatus::Resumable {
|
if thread.status() == LuaThreadStatus::Resumable {
|
||||||
let pending = lua.registry_value(&self.pending_key).unwrap();
|
let pending = lua
|
||||||
|
.registry_value(&self.pending_key)
|
||||||
|
.expect("ran out of memory");
|
||||||
let mut stream = thread.into_async::<_, LuaValue>(args);
|
let mut stream = thread.into_async::<_, LuaValue>(args);
|
||||||
|
|
||||||
// Keep resuming the thread until we get a
|
// Keep resuming the thread until we get a
|
||||||
|
|
Loading…
Add table
Reference in a new issue