Module on_server_idle_reduce.lua

📑 Source

Reduce a table asynchronously using idle callbacks.

This helper uses on_server_idle.lua to process each element over multiple frames, preventing long-running loops from causing lag.

Functions


# returns... (tbl, on_item, Initial[, on_done])

Parameters

  • tbl table Table to reduce.
  • on_item function Reduction function (acc, item) -> acc.
  • Initial acc accumulator value.
  • on_done on_done Optional callback called with the final accumulator. (optional)

Returns

    table Job object with a cancel() method.

Callbacks


# on_item (accumulated, item)
Called for each item in the provided table.

Parameters

  • accumulated any
  • item any

# on_done (accumulated)
Called after all items have been iterated.

Parameters

  • accumulated any