diff --git a/src/lune/scheduler/impl_async.rs b/src/lune/scheduler/impl_async.rs index 2754f40..eac200f 100644 --- a/src/lune/scheduler/impl_async.rs +++ b/src/lune/scheduler/impl_async.rs @@ -1,7 +1,7 @@ use futures_util::Future; use mlua::prelude::*; -use super::Scheduler; +use super::{IntoLuaOwnedThread, Scheduler}; impl<'lua, 'fut> Scheduler<'fut> where @@ -12,7 +12,7 @@ where */ pub fn schedule_future(&'fut self, fut: F) where - F: 'fut + Future, + F: Future + 'fut, { let futs = self .futures @@ -26,13 +26,14 @@ where */ pub fn schedule_future_thread( &'fut self, - thread: LuaOwnedThread, + thread: impl IntoLuaOwnedThread, fut: F, ) -> LuaResult<()> where FR: IntoLuaMulti<'fut>, - F: 'fut + Future>, + F: Future> + 'fut, { + let thread = thread.into_owned_lua_thread(&self.lua)?; self.schedule_future(async move { let rets = fut.await.expect("Failed to receive result"); let rets = rets diff --git a/src/lune/scheduler/traits.rs b/src/lune/scheduler/traits.rs index 9457843..0bf9ff8 100644 --- a/src/lune/scheduler/traits.rs +++ b/src/lune/scheduler/traits.rs @@ -25,8 +25,8 @@ where where A: FromLuaMulti<'lua>, R: IntoLuaMulti<'lua>, - F: 'static + Fn(&'lua Lua, A) -> FR, - FR: 'static + Future>; + F: Fn(&'lua Lua, A) -> FR + 'static, + FR: Future> + 'fut; } impl<'lua, 'fut> LuaSchedulerExt<'lua, 'fut> for Lua @@ -37,8 +37,8 @@ where where A: FromLuaMulti<'lua>, R: IntoLuaMulti<'lua>, - F: 'static + Fn(&'lua Lua, A) -> FR, - FR: 'static + Future>, + F: Fn(&'lua Lua, A) -> FR + 'static, + FR: Future> + 'fut, { let async_env = self.create_table_with_capacity(0, 2)?; @@ -52,12 +52,12 @@ where async_env.set( "schedule", LuaFunction::wrap(move |lua: &Lua, args: A| { - let _thread = lua.current_thread().into_owned(); - let _future = func(lua, args); - let _sched = lua + let thread = lua.current_thread(); + let future = func(lua, args); + let sched = lua .app_data_ref::<&Scheduler>() .expect("Lua struct is missing scheduler"); - // FIXME: `self` escapes outside of method + // FIXME: `self` escapes outside of method because we are borrowing `func`? // sched.schedule_future_thread(thread, future)?; Ok(()) }),