Skip to main content

AsyncCallHandle

Struct AsyncCallHandle 

Source
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

Source

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
Source

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.

Trait Implementations§

Source§

impl Drop for AsyncCallHandle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LuaMethodProvider for T

Source§

impl<T> LuaStaticMethodProvider for T

Source§

fn __lua_static_methods() -> &'static [(&'static str, CFunction)]

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.