Module on_server_idle.lua

📑 Source

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.

Functions


# on_server_idle.wrap (task_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

  • task_fn function Function to wrap.

Returns

    function Wrapped function that schedules fn on idle.

# on_server_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.

Tables


# on_server_idle
Module table

Fields

  • wrap wrap
  • run run
  • is_idle boolean True when the idle queue has budget to run tasks.
  • is_busy boolean False when idle