Petrichor.Task#
Petrichor.Task adds async/await on top of Luau coroutines. Timers, network results, and deferred work resume on the main Luau thread during petrichor_tick, the same thread that runs mod tick and hooks.
Background threads can do I/O. Luau only runs from the task scheduler tick, which keeps the VM safe.
Loading#
How it works#
Task.async(fn)returns a starter function.- Call
starter()to run the coroutine. - Inside the body,
Task.await(thunk)waits until the thunk callsstep(...)with resume values. - Built-in thunks:
Task.defer(),Task.delay(seconds).
Errors in the async body are logged with the async tag and include a Luau stack trace. They do not crash the game.
API#
Task.async(func) -> starter#
Builds a coroutine from func and returns starter. Call starter() to start it.
Task.await(thunk) -> ...#
Pauses until thunk(step) calls step(...). Those arguments become the return values of await.
Task.defer() -> thunk#
Resume on the next task batch, same thread, after the current hook or mod code returns.
Task.delay(seconds) -> thunk#
Resume after seconds of game time. Uses the real delta passed to petrichor_tick (Courage supplies DELTA_TIME / 30.0f).
Task.sleep(seconds) -> ...#
Same as Task.await(Task.delay(seconds)).
Task.on_hook does not exist yet. Register hooks in init and resume async work with Task.defer() or your own thunk.
Execution order#
Each frame:
petrichor::async::tick(L, delta) -- timers, deferred steps, net/hook resumes
mod instance:tick(delta) -- your mod tick methods
Task work runs before mod tick handlers.