Module on_server_idle

Run tasks when the server is idle (spread work across globalsteps).

This module provides a simple mechanism to queue work and execute it only when the globalstep has spare time, helping avoid lag spikes.

The module exposes two main interfaces: 1. A wrapper function to defer execution of a function. 2. A .run method to schedule a task immediately in the idle queue.

Functions

wrap (fn) Wrap a function so that it runs when the server is idle.
run (task_fn) Schedule a task to run when the server is idle.

Fields

is_idle Current idle state of the server.


Functions

wrap (fn)
Wrap a function so that it runs when the server is idle.

Returns a new function which, when called, schedules the original function to run later with any given arguments.

Parameters:

  • fn function Function to wrap.

Returns:

    function Wrapped function that schedules fn on idle.
run (task_fn)
Schedule a task to run when the server is idle.

The provided function will be invoked in a later globalstep, depending on how much spare time is available.

Parameters:

  • task_fn function Function receiving dtime as the first argument.

Fields

is_idle
Current idle state of the server. True when the idle queue has budget to run tasks.
  • is_idle bool
  • is_busy bool
generated by LDoc 1.5.0 Last updated 2026-03-13 21:12:31