Expand description
LuaSpawnerLayer — inserts middleware written in Lua into the SpawnerStack.
Shape:
before_src= a Lua source that evaluates to a function. Called immediately before the spawn asfunction(ctx_table) ... end. If it raises, the spawn is rejected withSpawnError::RejectedByMiddleware(a gate).after_src= a Lua source that evaluates tofunction(ctx_table, result_table) return result' end, called after the worker finishes; the return value becomes the new result flowing downstream (a transform).
§Implementation axis
mlua::Lua is !Send, so the initial form built a fresh Lua::new()
per call and dropped it (per-call VM). Under high-frequency spawn the
overhead becomes visible. This version switches to
mlua-isle::AsyncIslePool (thread-isolated Lua VM + async + pool) and
reuses VMs from the pool. The fully-async chain stays the same shape
(no block_on / spawn_blocking); the !Send constraint is resolved
inside the isle so it rides on the caller’s tokio runtime directly.
Structs§
- LuaMiddleware
SpawnerLayerthat runs Lua source as a before-gate and/or an after-transform around a spawn, executed on a pooledAsyncIslePoolVM. See the module doc for the exact function shapes expected ofbefore_src/after_src.