Add back lua lifetime to scheduler

This commit is contained in:
Filip Tibell 2023-08-18 13:57:31 -05:00
parent 6e83958653
commit 0dbf466817
5 changed files with 8 additions and 8 deletions

View file

@ -3,7 +3,7 @@ use mlua::prelude::*;
use super::{IntoLuaOwnedThread, Scheduler}; use super::{IntoLuaOwnedThread, Scheduler};
impl<'lua, 'fut> Scheduler<'fut> impl<'lua, 'fut> Scheduler<'lua, 'fut>
where where
'lua: 'fut, 'lua: 'fut,
{ {

View file

@ -7,7 +7,7 @@ use tokio::task::LocalSet;
use super::Scheduler; use super::Scheduler;
impl<'lua, 'fut> Scheduler<'fut> impl<'lua, 'fut> Scheduler<'lua, 'fut>
where where
'lua: 'fut, 'lua: 'fut,
{ {

View file

@ -7,7 +7,7 @@ use super::{
IntoLuaOwnedThread, Scheduler, IntoLuaOwnedThread, Scheduler,
}; };
impl<'lua, 'fut> Scheduler<'fut> impl<'lua, 'fut> Scheduler<'lua, 'fut>
where where
'lua: 'fut, 'lua: 'fut,
{ {

View file

@ -33,16 +33,16 @@ type SchedulerFuture<'fut> = Pin<Box<dyn Future<Output = ()> + 'fut>>;
and data will remain unchanged and accessible from all clones. and data will remain unchanged and accessible from all clones.
*/ */
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct Scheduler<'fut> { pub(crate) struct Scheduler<'lua, 'fut> {
lua: &'static Lua, lua: &'lua Lua,
state: Arc<SchedulerState>, state: Arc<SchedulerState>,
threads: Arc<RefCell<VecDeque<SchedulerThread>>>, threads: Arc<RefCell<VecDeque<SchedulerThread>>>,
thread_senders: Arc<RefCell<HashMap<SchedulerThreadId, SchedulerThreadSender>>>, thread_senders: Arc<RefCell<HashMap<SchedulerThreadId, SchedulerThreadSender>>>,
futures: Arc<AsyncMutex<FuturesUnordered<SchedulerFuture<'fut>>>>, futures: Arc<AsyncMutex<FuturesUnordered<SchedulerFuture<'fut>>>>,
} }
impl<'fut> Scheduler<'fut> { impl<'lua, 'fut> Scheduler<'lua, 'fut> {
pub fn new(lua: &'static Lua) -> Self { pub fn new(lua: &'lua Lua) -> Self {
Self { Self {
lua, lua,
state: Arc::new(SchedulerState::new()), state: Arc::new(SchedulerState::new()),

View file

@ -55,7 +55,7 @@ impl LuaSchedulerExt for Lua {
.app_data_ref::<&Scheduler>() .app_data_ref::<&Scheduler>()
.expect("Lua struct is missing scheduler"); .expect("Lua struct is missing scheduler");
// FIXME: `self` escapes outside of method because we are borrowing `func`? // FIXME: `self` escapes outside of method because we are borrowing `func`?
// For now we solve this by just using a &'static Lua reference everywhere // For now we solve this by using 'static lifetimes for this entire method
sched.schedule_future_thread(thread, future)?; sched.schedule_future_thread(thread, future)?;
Ok(()) Ok(())
}), }),