pub struct AsyncCallHandle { /* private fields */ }Expand description
A reusable async call handle that keeps a runner coroutine alive across multiple calls to the same Lua function.
Created via LuaVM::create_async_call_handle or
LuaVM::create_async_call_handle_global.
Unlike LuaVM::call_async which creates a new coroutine for each
invocation, AsyncCallHandle reuses a single coroutine, reducing GC
pressure and allocation overhead for repeated calls.
The runner uses pcall internally, so Lua errors in the target function
are caught and returned as Err without invalidating the handle. Only
infrastructure failures (async future errors, coroutine death) mark the
handle as dead.
§Example
let mut handle = vm.create_async_call_handle_global("process")?;
for item in items {
let arg = vm.create_string(&item)?;
let result = handle.call(vec![arg]).await?;
}Implementations§
Source§impl AsyncCallHandle
impl AsyncCallHandle
Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Returns true if the handle is still usable for calls.
A handle becomes dead if:
- An async future returned an error
- The runner coroutine terminated unexpectedly
Sourcepub async fn call(&mut self, args: Vec<LuaValue>) -> LuaResult<Vec<LuaValue>>
pub async fn call(&mut self, args: Vec<LuaValue>) -> LuaResult<Vec<LuaValue>>
Call the wrapped function with the given arguments.
Drives the runner coroutine, handling async yields transparently. Returns the function’s return values on success.
If the target function raises a Lua error, it is caught by the internal
pcall and returned as Err, but the handle remains alive for
future calls. If an async future fails or the coroutine dies, the handle
is marked as dead and subsequent calls return an error immediately.