Skip to main content

Module lua_layer

Module lua_layer 

Source
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 as function(ctx_table) ... end. If it raises, the spawn is rejected with SpawnError::RejectedByMiddleware (a gate).
  • after_src = a Lua source that evaluates to function(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
SpawnerLayer that runs Lua source as a before-gate and/or an after-transform around a spawn, executed on a pooled AsyncIslePool VM. See the module doc for the exact function shapes expected of before_src / after_src.