From 22c973af02826dba3b6401b873589f44a0f3374e Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Fri, 3 Mar 2023 18:22:30 +0000 Subject: [PATCH] Async: Don't clone function when executing it from recycled thread --- src/function.rs | 2 +- src/lua.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/function.rs b/src/function.rs index 13d1efb..9302cbb 100644 --- a/src/function.rs +++ b/src/function.rs @@ -178,7 +178,7 @@ impl<'lua> Function<'lua> { R: FromLuaMulti<'lua> + 'fut, { let lua = self.0.lua; - match lua.create_recycled_thread(self.clone()) { + match lua.create_recycled_thread(self) { Ok(t) => { let mut t = t.into_async(args); t.set_recyclable(true); diff --git a/src/lua.rs b/src/lua.rs index bf9ab13..864095b 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -1632,7 +1632,7 @@ impl Lua { /// Wraps a Lua function into a new thread (or coroutine). /// /// Equivalent to `coroutine.create`. - pub fn create_thread<'lua>(&'lua self, func: Function<'lua>) -> Result> { + pub fn create_thread<'lua>(&'lua self, func: Function) -> Result> { let state = self.state(); unsafe { let _sg = StackGuard::new(state); @@ -1654,7 +1654,7 @@ impl Lua { #[cfg(feature = "async")] pub(crate) fn create_recycled_thread<'lua>( &'lua self, - func: Function<'lua>, + func: &Function, ) -> Result> { #[cfg(any( feature = "lua54", @@ -1681,7 +1681,7 @@ impl Lua { return Ok(Thread(LuaRef::new(self, index))); } }; - self.create_thread(func) + self.create_thread(func.clone()) } /// Resets thread (coroutine) and returns to the pool for later use.