AbstractStaticrunFunction to execute after the delay.
Delay in Ticks (20 ticks = 1 second).
OptionalprofileLabel: stringOptional profiling label. If provided, the callback is wrapped with DebugTimerUtil.start / DebugTimerUtil.stop.
The timeout ID from system.runTimeout.
// Run once after 40 ticks (2 seconds)
TimerUtil.runTimeout(() => doSomethingOnce(), 40);
// Run once after 20 ticks with profiling
TimerUtil.runTimeout(() => showcaseProfiling(), 20, "showcaseProfiling.once");
profileLabel is provided, the callback is wrapped with
DebugTimerUtil.start / DebugTimerUtil.stop.<= 1 runs immediately when triggered.> 1 may be load-spread across nearby ticks during heavy contention.2-10 ticks prefer the short lane,
>10 ticks use the long lane.0-1 tick) to reduce
synchronized burst execution.callback is not a function or delay is not a non-negative number.StaticrunRepeats a callback every delay ticks.
options.name to allow later control via TimerUtil.clear,
statistics via TimerUtil.getNamedIntervalStats, and to prevent accidental duplicates.options.name. Useful for quick, fire-and-forget repeating work.Function to execute each interval.
Period in Ticks (20 ticks = 1 second).
See NamedIntervalOptions and IntervalOptions.
The interval ID from system.runInterval.
// Anonymous interval, every 20 ticks
const id = TimerUtil.runInterval(() => everySecondThisRuns(), 20);
// Named interval with profiling and an immediate first run
TimerUtil.runInterval(() => refreshStats(), 10, {
name: "StatsRefresh",
beginImmediately: true,
profile: true, // uses name as profile label
});
// Replace an existing named interval
TimerUtil.runInterval(() => rescan(), 5, { name: "Scanner", force: true, profile: "scanner" });
beginImmediately is true, the callback runs once before scheduling.options.profile:
true > uses the interval's name (or "anonymous_interval" for anonymous).string > uses the provided label.<= 1 runs immediately when triggered.> 1 may be load-spread across nearby ticks during heavy contention.force: true throws.callback is not a function or delay is not a non-negative number.Repeats a callback every delay ticks.
options.name to allow later control via TimerUtil.clear,
statistics via TimerUtil.getNamedIntervalStats, and to prevent accidental duplicates.options.name. Useful for quick, fire-and-forget repeating work.Function to execute each interval.
Period in Ticks (20 ticks = 1 second).
Optionaloptions: IntervalOptionsSee NamedIntervalOptions and IntervalOptions.
The interval ID from system.runInterval.
// Anonymous interval, every 20 ticks
const id = TimerUtil.runInterval(() => everySecondThisRuns(), 20);
// Named interval with profiling and an immediate first run
TimerUtil.runInterval(() => refreshStats(), 10, {
name: "StatsRefresh",
beginImmediately: true,
profile: true, // uses name as profile label
});
// Replace an existing named interval
TimerUtil.runInterval(() => rescan(), 5, { name: "Scanner", force: true, profile: "scanner" });
beginImmediately is true, the callback runs once before scheduling.options.profile:
true > uses the interval's name (or "anonymous_interval" for anonymous).string > uses the provided label.<= 1 runs immediately when triggered.> 1 may be load-spread across nearby ticks during heavy contention.force: true throws.callback is not a function or delay is not a non-negative number.StaticnextSchedule a callback on the next tick.
Function to run next tick.
OptionalprofileLabel: stringOptional profiling label. Wraps the callback with DebugTimerUtil.start / DebugTimerUtil.stop.
The ID from system.run.
profileLabel is provided, the callback is wrapped with
DebugTimerUtil.start / DebugTimerUtil.stop.callback is not a function.StaticrunSchedule a timeout by key where the latest schedule replaces any previous pending timeout.
Logical key for deduplication.
Callback to run.
Delay in ticks.
OptionalprofileLabel: stringOptional profiling label.
The timeout ID for the latest scheduled callback.
StaticclearCancel a pending latest-timeout callback by key.
Key used with runLatestTimeout.
StaticgetRead live timer scheduler metrics for tuning.
StaticclearClear a scheduled interval by name (named intervals) or by ID (anonymous or named).
The interval ID (from runInterval) or the name provided in NamedIntervalOptions.
// Clear by ID
const id = TimerUtil.runInterval(() => tick(), 20);
TimerUtil.clear(id);
// Clear by name
TimerUtil.runInterval(() => refresh(), 10, { name: "StatsRefresh" });
TimerUtil.clear("StatsRefresh");
string is passed, it is treated as the name of a named interval.number is passed, it is treated as the interval ID returned by runInterval.StaticclearClear all currently active named intervals.
name in NamedIntervalOptions.StaticgetGet rolling performance statistics for a named interval.
The interval name used when creating it.
NamedIntervalStats with averageTime and maxTime (ms) computed
over the recent execution window, or undefined if no such interval exists.
StaticlistList the names of all active named intervals.
An array of names corresponding to active named intervals.
Schedule a one-off callback after a specified delay (in ticks).