A Roblox-like scheduler for mlua
- Tokio support + minimal CPU usage
- Correctness and performance are king
- Simple with simple primitives for getting results out.
- Properly working
coroutine.yield
andcoroutine.resume
functions that produce equivalent (mostly) results in Roblox's own Luau + Task Scheduling code - Both mlua non-send and send features supported (thanks to rust async wizardry).
- Custom async function handling that works with Lua's coroutine design paradigm without breaking on edge-cases.
- Simple callback API for controlling the scheduler (
SchedulerFeedback
trait)
- Thread arguments are not preloaded to the stack due to mlua limitations. This is normally not a problem but may cause side-effects. For example, see the below.
local task = task or require("@lune/task")
local thread = task.delay(1, function(foo)
print(foo)
print(coroutine.yield())
print("c")
print(coroutine.yield())
print("e")
end, "b")
task.spawn(thread, "a")
task.delay(2, function()
coroutine.resume(thread, "d")
end)
mlua_scheduler has two scheduler versions. v1 (the original scheduler which used busy poll loop/spinloop that ran every tick to run through tasks) and v2 which is a new scheduler design based on tokio select and delayqueue/tokio channels without any busy polling. Here are the differences:
mluau_scheduler no longer supports the v1 scheduler. The v2 scheduler is the only one supported and is the default.
- V2 scheduler is based on the Tokio runtime and uses its async features.
- V2 scheduler is more efficient and does not use busy polling.
- V2 scheduler is more robust and can handle more complex tasks with minimal performance loss to the v1 scheduler.