From 0dbf4668172789f67785cc7d2f5de38671e7bc23 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Fri, 18 Aug 2023 13:57:31 -0500 Subject: [PATCH] Add back lua lifetime to scheduler --- src/lune/scheduler/impl_async.rs | 2 +- src/lune/scheduler/impl_runner.rs | 2 +- src/lune/scheduler/impl_threads.rs | 2 +- src/lune/scheduler/mod.rs | 8 ++++---- src/lune/scheduler/traits.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lune/scheduler/impl_async.rs b/src/lune/scheduler/impl_async.rs index cf14abd..9ae53a5 100644 --- a/src/lune/scheduler/impl_async.rs +++ b/src/lune/scheduler/impl_async.rs @@ -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, { diff --git a/src/lune/scheduler/impl_runner.rs b/src/lune/scheduler/impl_runner.rs index 2554c4a..088bf23 100644 --- a/src/lune/scheduler/impl_runner.rs +++ b/src/lune/scheduler/impl_runner.rs @@ -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, { diff --git a/src/lune/scheduler/impl_threads.rs b/src/lune/scheduler/impl_threads.rs index 5184576..2f8969f 100644 --- a/src/lune/scheduler/impl_threads.rs +++ b/src/lune/scheduler/impl_threads.rs @@ -7,7 +7,7 @@ use super::{ IntoLuaOwnedThread, Scheduler, }; -impl<'lua, 'fut> Scheduler<'fut> +impl<'lua, 'fut> Scheduler<'lua, 'fut> where 'lua: 'fut, { diff --git a/src/lune/scheduler/mod.rs b/src/lune/scheduler/mod.rs index 0231f38..2bbb373 100644 --- a/src/lune/scheduler/mod.rs +++ b/src/lune/scheduler/mod.rs @@ -33,16 +33,16 @@ type SchedulerFuture<'fut> = Pin + '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, threads: Arc>>, thread_senders: Arc>>, futures: Arc>>>, } -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()), diff --git a/src/lune/scheduler/traits.rs b/src/lune/scheduler/traits.rs index b79382b..fad4f24 100644 --- a/src/lune/scheduler/traits.rs +++ b/src/lune/scheduler/traits.rs @@ -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(()) }),