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
fnon 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
dtimeas the first argument.
- task_fn
function
Function receiving