OPX//77
opx_infinityConcepts

The scheduler

Last updated on

OPX.Scheduler.Every is how a module runs repeating work on the server and on the client, and the two implementations behave differently.

Use OPX.Scheduler for repeating work instead of CreateThread(function() while true do ... Wait(n) end end). Same four functions on both sides, implemented differently because the two runtimes fail differently.

local handle = OPX.Scheduler.Every('mymodule.sweep', 1000, function()
	-- runs about once a second
end)
OPX.Scheduler.Cancel(handle)   -- in M.Stop
FunctionServerClient
Every(name, intervalMs, step)One managed task per job. intervalMs is a number or a function re-read every pass (to follow a live tunable).One shared loop for every job. intervalMs must be a number; a function raises. 0 = every pass.
Cancel(handle)Stops the job.Stops the job; it is dropped at the next pass.
Report()One line per job.One line per job: name, interval, running/stopped.
Stop()Stops every job (resource stop).Stops the loop (resource stop).

name only appears in log lines; write it as <module>.<purpose>.

Server behaviour

RuleValue
First runOne interval after registration, never at once.
Smallest interval50 ms. A smaller value is raised to 50.
Interval that cannot be readRuns at its last good interval, or every 60 s, and logs once.
A step that raisesLogged once per run of failures. The job is never suspended.

Client behaviour

RuleValue
Jobs per passAt most 4 due jobs per resume, in rotation, so none starves.
First runStaggered, so jobs on the same interval do not land on the same frame.
A step that raisesLogged on the first and third failure. After 3 failures in a row the job is suspended (cancelled): [scheduler] <name> suspended after 3 failures.
IdleThe loop sleeps at most 100 ms between passes.

The client loop starts after every module's Start (OPX.Scheduler.Start). /opx.client in the client console prints the job list.

Keep each client step small

All client jobs share the loop. A step that walks a long list every frame can exceed the client's instruction budget, and the platform then kills the coroutine without any log line. Spread long work over several passes (Two runtimes).

On this page