Optimize async functionality:

Rewrite using the new `push_into_stack()`/`from_stack()` methods.
Also store thread state (pointer) in `Thread` struct to avoid getting it every time.
Async userdata methods still need to have arguments stored in ref thread as stack is empty on every poll().
This commit is contained in:
Alex Orlenko
2023-08-03 00:56:17 +01:00
parent 4fff14a144
commit cd0c8a4584
10 changed files with 289 additions and 296 deletions
+3 -3
View File
@@ -598,13 +598,13 @@ impl<'lua> Function<'lua> {
F: Fn(&'lua Lua, A) -> FR + MaybeSend + 'static,
FR: Future<Output = Result<R>> + 'lua,
{
WrappedAsyncFunction(Box::new(move |lua, args| {
let args = match A::from_lua_multi(args, lua) {
WrappedAsyncFunction(Box::new(move |lua, args| unsafe {
let args = match A::from_lua_args(args, 1, None, lua) {
Ok(args) => args,
Err(e) => return Box::pin(future::err(e)),
};
let fut = func(lua, args);
Box::pin(async move { fut.await?.into_lua_multi(lua) })
Box::pin(async move { fut.await?.push_into_stack_multi(lua) })
}))
}
}