API reference / @jsprismarine/prismarine / modules/ticker / ServerTicker
Class: ServerTicker
Defined in: packages/prismarine/src/modules/ticker.ts:260
The fixed-epoch tick loop. start() begins ticking immediately (unless the server runs with ticking disabled) and stop() clears the pending timer; the counters survive a stop, so a restart resumes the tick number while the schedule restarts from a fresh epoch instead of repaying the downtime as a catch-up burst.
Implements
Constructors
Constructor
new ServerTicker(
server,now?):ServerTicker
Defined in: packages/prismarine/src/modules/ticker.ts:293
Parameters
server
What the loop drives.
now?
() => number
A monotonic clock in milliseconds. Monotonic, not wall clock: Date.now() follows the system time, and an NTP correction or a VM resume moves it under the scheduler. A forward step used to read as accumulated lateness and trigger a catch-up burst; a backward one as time to kill, stalling the server for the size of the step.
Returns
ServerTicker
Properties
recorder
readonlyrecorder:TickRecorder
Defined in: packages/prismarine/src/modules/ticker.ts:281
The most recent ticks' duration, lateness and phases, for profiles and benchmarks.
Methods
advance()
advance():
void
Defined in: packages/prismarine/src/modules/ticker.ts:580
Runs one tick by hand, outside the loop's schedule, to its end in one call.
For a harness that drives a server with ticking disabled, such as a replay: each call is exactly one tick, whatever the host's speed, so two runs of the same input take the same steps. It runs the same work, in the same order, as a tick of the loop.
The harness activates the chunk completion queue before its first step, as start does for the loop. While the queue is inactive, inputs and finished chunks are applied when they arrive rather than held for the next input step.
Returns
void
Throws
While the loop runs, or when called from inside the tick it is running.
getLastTickMs()
getLastTickMs():
number
Defined in: packages/prismarine/src/modules/ticker.ts:319
The last tick's work duration in milliseconds; see Ticker.getLastTickMs.
Returns
number
Implementation of
getTick()
getTick():
number
Defined in: packages/prismarine/src/modules/ticker.ts:299
The current tick number.
Returns
number
Implementation of
getTickMs()
getTickMs():
number
Defined in: packages/prismarine/src/modules/ticker.ts:314
The smoothed per-tick work duration in milliseconds; see Ticker.getTickMs.
Returns
number
Implementation of
getTickRate()
getTickRate():
number
Defined in: packages/prismarine/src/modules/ticker.ts:324
The ticks per second the loop aims for.
Returns
number
Implementation of
getTPS()
getTPS():
number
Defined in: packages/prismarine/src/modules/ticker.ts:304
The current TPS, measured over a sliding one-second window.
Returns
number
Implementation of
getTPSAverages()
getTPSAverages():
number[]
Defined in: packages/prismarine/src/modules/ticker.ts:309
The TPS averaged over the last 1, 5 and 15 minutes; see Ticker.getTPSAverages.
Returns
number[]
Implementation of
hold()
hold():
void
Defined in: packages/prismarine/src/modules/ticker.ts:376
Keeps the loop from starting until ServerTicker.release. The server holds it while it starts, so no tick runs before every transport listens.
Returns
void
isFrozen()
isFrozen():
boolean
Defined in: packages/prismarine/src/modules/ticker.ts:335
Whether the world and functions are held still.
Returns
boolean
Implementation of
release()
release():
void
Defined in: packages/prismarine/src/modules/ticker.ts:381
Lets the loop start, and starts it if a start() was held back.
Returns
void
setFrozen()
setFrozen(
frozen):void
Defined in: packages/prismarine/src/modules/ticker.ts:340
Freezes or unfreezes the world, dropping any step in progress.
Parameters
frozen
boolean
Returns
void
Implementation of
setTickRate()
setTickRate(
rate):void
Defined in: packages/prismarine/src/modules/ticker.ts:329
Sets the target ticks per second; the schedule restarts from now at the new period.
Parameters
rate
number
Returns
void
Implementation of
sprint()
sprint(
ticks):void
Defined in: packages/prismarine/src/modules/ticker.ts:360
Runs ticks ticks back to back, then returns to the target rate.
Parameters
ticks
number
Returns
void
Implementation of
start()
start():
void
Defined in: packages/prismarine/src/modules/ticker.ts:391
Starts the loop; a no-op when ticking is disabled or the loop already runs.
Returns
void
step()
step(
ticks):boolean
Defined in: packages/prismarine/src/modules/ticker.ts:346
Lets ticks ticks through a frozen world; false when the world is running.
Parameters
ticks
number
Returns
boolean
Implementation of
stop()
stop():
void
Defined in: packages/prismarine/src/modules/ticker.ts:787
Stops the loop: clears the pending timer and stops a tick in flight from rescheduling.
Returns
void
stopSprint()
stopSprint():
boolean
Defined in: packages/prismarine/src/modules/ticker.ts:365
Ends a sprint early; false when none was running.
Returns
boolean
Implementation of
stopStep()
stopStep():
boolean
Defined in: packages/prismarine/src/modules/ticker.ts:353
Ends a step early; false when none was running.
Returns
boolean