mirror of
https://github.com/lune-org/lune.git
synced 2025-03-02 18:23:36 +00:00
Some lifetime and async arg improvements
This commit is contained in:
parent
62e6130223
commit
e1fa89cf60
2 changed files with 13 additions and 12 deletions
|
@ -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<F>(&'fut self, fut: F)
|
||||
where
|
||||
F: 'fut + Future<Output = ()>,
|
||||
F: Future<Output = ()> + 'fut,
|
||||
{
|
||||
let futs = self
|
||||
.futures
|
||||
|
@ -26,13 +26,14 @@ where
|
|||
*/
|
||||
pub fn schedule_future_thread<F, FR>(
|
||||
&'fut self,
|
||||
thread: LuaOwnedThread,
|
||||
thread: impl IntoLuaOwnedThread,
|
||||
fut: F,
|
||||
) -> LuaResult<()>
|
||||
where
|
||||
FR: IntoLuaMulti<'fut>,
|
||||
F: 'fut + Future<Output = LuaResult<FR>>,
|
||||
F: Future<Output = LuaResult<FR>> + '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
|
||||
|
|
|
@ -25,8 +25,8 @@ where
|
|||
where
|
||||
A: FromLuaMulti<'lua>,
|
||||
R: IntoLuaMulti<'lua>,
|
||||
F: 'static + Fn(&'lua Lua, A) -> FR,
|
||||
FR: 'static + Future<Output = LuaResult<R>>;
|
||||
F: Fn(&'lua Lua, A) -> FR + 'static,
|
||||
FR: Future<Output = LuaResult<R>> + '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<Output = LuaResult<R>>,
|
||||
F: Fn(&'lua Lua, A) -> FR + 'static,
|
||||
FR: Future<Output = LuaResult<R>> + '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(())
|
||||
}),
|
||||
|
|
Loading…
Add table
Reference in a new issue