Async: Don't clone function when executing it from recycled thread

This commit is contained in:
Alex Orlenko 2023-03-03 18:22:30 +00:00
parent 8c18fa1764
commit 22c973af02
No known key found for this signature in database
GPG Key ID: 4C150C250863B96D
2 changed files with 4 additions and 4 deletions

View File

@ -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);

View File

@ -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<Thread<'lua>> {
pub fn create_thread<'lua>(&'lua self, func: Function) -> Result<Thread<'lua>> {
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<Thread<'lua>> {
#[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.