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};
impl<'lua, 'fut> Scheduler<'fut>
impl<'lua, 'fut> Scheduler<'lua, 'fut>
where
'lua: 'fut,
{

View file

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

View file

@ -7,7 +7,7 @@ use super::{
IntoLuaOwnedThread, Scheduler,
};
impl<'lua, 'fut> Scheduler<'fut>
impl<'lua, 'fut> Scheduler<'lua, 'fut>
where
'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.
*/
#[derive(Debug, Clone)]
pub(crate) struct Scheduler<'fut> {
lua: &'static Lua,
pub(crate) struct Scheduler<'lua, 'fut> {
lua: &'lua Lua,
state: Arc<SchedulerState>,
threads: Arc<RefCell<VecDeque<SchedulerThread>>>,
thread_senders: Arc<RefCell<HashMap<SchedulerThreadId, SchedulerThreadSender>>>,
futures: Arc<AsyncMutex<FuturesUnordered<SchedulerFuture<'fut>>>>,
}
impl<'fut> Scheduler<'fut> {
pub fn new(lua: &'static Lua) -> Self {
impl<'lua, 'fut> Scheduler<'lua, 'fut> {
pub fn new(lua: &'lua Lua) -> Self {
Self {
lua,
state: Arc::new(SchedulerState::new()),

View file

@ -55,7 +55,7 @@ impl LuaSchedulerExt for Lua {
.app_data_ref::<&Scheduler>()
.expect("Lua struct is missing scheduler");
// 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)?;
Ok(())
}),