[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / [modules/ticker](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md) / ServerTicker

# Class: ServerTicker

Defined in: [packages/prismarine/src/modules/ticker.ts:260](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L260)

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

- [`Ticker`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#ticker)
- [`TickControl`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#tickcontrol)

## Constructors

### Constructor

> **new ServerTicker**(`server`, `now?`): `ServerTicker`

Defined in: [packages/prismarine/src/modules/ticker.ts:293](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L293)

#### Parameters

##### server

[`TickerServer`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#tickerserver)

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

> `readonly` **recorder**: [`TickRecorder`](https://jsprismarine.dev/api/@jsprismarine/prismarine/profiling/TickRecorder/classes/TickRecorder.md)

Defined in: [packages/prismarine/src/modules/ticker.ts:281](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L281)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L580)

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](#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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L319)

The last tick's work duration in milliseconds; see [Ticker.getLastTickMs](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#getlasttickms).

#### Returns

`number`

#### Implementation of

[`Ticker`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#ticker).[`getLastTickMs`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#getlasttickms)

***

### getTick()

> **getTick**(): `number`

Defined in: [packages/prismarine/src/modules/ticker.ts:299](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L299)

The current tick number.

#### Returns

`number`

#### Implementation of

[`Ticker`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#ticker).[`getTick`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#gettick)

***

### getTickMs()

> **getTickMs**(): `number`

Defined in: [packages/prismarine/src/modules/ticker.ts:314](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L314)

The smoothed per-tick work duration in milliseconds; see [Ticker.getTickMs](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#gettickms).

#### Returns

`number`

#### Implementation of

[`Ticker`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#ticker).[`getTickMs`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#gettickms)

***

### getTickRate()

> **getTickRate**(): `number`

Defined in: [packages/prismarine/src/modules/ticker.ts:324](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L324)

The ticks per second the loop aims for.

#### Returns

`number`

#### Implementation of

[`TickControl`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#tickcontrol).[`getTickRate`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#gettickrate)

***

### getTPS()

> **getTPS**(): `number`

Defined in: [packages/prismarine/src/modules/ticker.ts:304](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L304)

The current TPS, measured over a sliding one-second window.

#### Returns

`number`

#### Implementation of

[`Ticker`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#ticker).[`getTPS`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#gettps)

***

### getTPSAverages()

> **getTPSAverages**(): `number`[]

Defined in: [packages/prismarine/src/modules/ticker.ts:309](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L309)

The TPS averaged over the last 1, 5 and 15 minutes; see [Ticker.getTPSAverages](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#gettpsaverages).

#### Returns

`number`[]

#### Implementation of

[`Ticker`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#ticker).[`getTPSAverages`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#gettpsaverages)

***

### hold()

> **hold**(): `void`

Defined in: [packages/prismarine/src/modules/ticker.ts:376](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L376)

Keeps the loop from starting until [ServerTicker.release](#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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L335)

Whether the world and functions are held still.

#### Returns

`boolean`

#### Implementation of

[`TickControl`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#tickcontrol).[`isFrozen`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#isfrozen)

***

### release()

> **release**(): `void`

Defined in: [packages/prismarine/src/modules/ticker.ts:381](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L381)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L340)

Freezes or unfreezes the world, dropping any step in progress.

#### Parameters

##### frozen

`boolean`

#### Returns

`void`

#### Implementation of

[`TickControl`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#tickcontrol).[`setFrozen`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#setfrozen)

***

### setTickRate()

> **setTickRate**(`rate`): `void`

Defined in: [packages/prismarine/src/modules/ticker.ts:329](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L329)

Sets the target ticks per second; the schedule restarts from now at the new period.

#### Parameters

##### rate

`number`

#### Returns

`void`

#### Implementation of

[`TickControl`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#tickcontrol).[`setTickRate`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#settickrate)

***

### sprint()

> **sprint**(`ticks`): `void`

Defined in: [packages/prismarine/src/modules/ticker.ts:360](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L360)

Runs `ticks` ticks back to back, then returns to the target rate.

#### Parameters

##### ticks

`number`

#### Returns

`void`

#### Implementation of

[`TickControl`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#tickcontrol).[`sprint`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#sprint)

***

### start()

> **start**(): `void`

Defined in: [packages/prismarine/src/modules/ticker.ts:391](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L391)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L346)

Lets `ticks` ticks through a frozen world; false when the world is running.

#### Parameters

##### ticks

`number`

#### Returns

`boolean`

#### Implementation of

[`TickControl`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#tickcontrol).[`step`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#step)

***

### stop()

> **stop**(): `void`

Defined in: [packages/prismarine/src/modules/ticker.ts:787](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L787)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L365)

Ends a sprint early; false when none was running.

#### Returns

`boolean`

#### Implementation of

[`TickControl`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#tickcontrol).[`stopSprint`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#stopsprint)

***

### stopStep()

> **stopStep**(): `boolean`

Defined in: [packages/prismarine/src/modules/ticker.ts:353](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/modules/ticker.ts#L353)

Ends a step early; false when none was running.

#### Returns

`boolean`

#### Implementation of

[`TickControl`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#tickcontrol).[`stopStep`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/index.md#stopstep)
