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

# modules/ticker

## Classes

- [ServerTicker](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/classes/ServerTicker.md)

## Interfaces

### TickControl

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

What `/tick` can do to the loop: the rate it aims for, whether the world advances, and bursts of ticks.

#### Methods

##### getTickRate()

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

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

The ticks per second the loop aims for.

###### Returns

`number`

##### isFrozen()

> **isFrozen**(): `boolean`

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

Whether the world and functions are held still. Tick events and chunk sends carry on.

###### Returns

`boolean`

##### setFrozen()

> **setFrozen**(`frozen`): `void`

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

###### Parameters

###### frozen

`boolean`

###### Returns

`void`

##### setTickRate()

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

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

Sets the target ticks per second; a loop that is sprinting keeps sprinting.

###### Parameters

###### rate

`number`

###### Returns

`void`

##### sprint()

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

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

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

###### Parameters

###### ticks

`number`

###### Returns

`void`

##### step()

> **step**(`ticks`): `boolean`

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

Runs `ticks` ticks of a frozen world, then freezes it again.

###### Parameters

###### ticks

`number`

###### Returns

`boolean`

False when the world is not frozen, so there is nothing to step.

##### stopSprint()

> **stopSprint**(): `boolean`

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

Ends a sprint early.

###### Returns

`boolean`

False when no sprint was running.

##### stopStep()

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

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

Ends a step early.

###### Returns

`boolean`

False when no step was running.

***

### Ticker

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

What the `prismarine:ticker` token resolves to: the running tick counters.
Tick work itself is observed through the server's typed `tick` event, which
the loop emits in every tick, after the input step.

#### Methods

##### getLastTickMs()

> **getLastTickMs**(): `number`

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

How long the last tick's work took, in milliseconds, without the sleep before the next
tick. Zero until the first tick completes.

###### Returns

`number`

##### getTick()

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

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

The current tick number.

###### Returns

`number`

##### getTickMs()

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

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

How long a tick's work has been taking, in milliseconds, as a moving average
over the most recent ticks. It leaves out the sleep between ticks, so a healthy
server reads well under the 50 ms period. Zero until the first tick completes.

###### Returns

`number`

##### getTPS()

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

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

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

###### Returns

`number`

##### getTPSAverages()

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

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

The TPS averaged over the last 1, 5 and 15 minutes ([TPS\_AVERAGE\_MINUTES](#tps-average-minutes)), as
exponential moving averages of one sample every 100 ticks, the way Spigot's `/tps` measures
them. Each starts at the default 20 and moves toward the measured rate as samples arrive.

###### Returns

`number`[]

***

### TickerServer

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

The slice of the server the tick loop drives. Everything here is a collaborator
that is not a kernel module yet; as each one converts, its accessor should be
replaced by a service token the ticker module declares as a dependency:

- `getWorlds` belongs to a future worlds token (the world manager).
- `tickFunctions` belongs to a future commands token (the command manager).
- `getChunkScheduler` belongs to a future chunk-scheduler token.
- `getChunkSendBudgetMs`, `isTickingEnabled`, and `isProcessTitleEnabled`
  belong to a future config token (or the ticker module's config slice).

#### Properties

##### events

> `readonly` **events**: `Pick`\<[`ServerEventBus`](https://jsprismarine.dev/api/@jsprismarine/prismarine/events/ServerEvents/index.md#servereventbus), `"post"`\>

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

The kernel's event bus, which the ticker posts the server `tick` event on inside the tick,
waiting for no listener.

#### Methods

##### admitInputs()

> **admitInputs**(): `number`

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

The input step: applies the inputs held since the last tick, in arrival order, up to a
count, then the chunk completions it admits. The ticker runs it before anything else in
the tick, and before any world updates.

###### Returns

`number`

##### getChunkCompletionQueue()

> **getChunkCompletionQueue**(): `Pick`\<[`ChunkCompletionQueue`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/ChunkCompletionQueue/classes/ChunkCompletionQueue.md), `"activate"` \| `"deactivate"` \| `"drain"`\>

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

Deferred worker translations and background lighting, budgeted separately from packet sends.

###### Returns

`Pick`\<[`ChunkCompletionQueue`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/ChunkCompletionQueue/classes/ChunkCompletionQueue.md), `"activate"` \| `"deactivate"` \| `"drain"`\>

##### getChunkScheduler()

> **getChunkScheduler**(): `object`

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

The server-wide chunk scheduler the tick hands a time slice to.

###### Returns

###### setBudget()

> **setBudget**(`budgetMs`): `void`

###### Parameters

###### budgetMs

`number`

###### Returns

`void`

###### tick()

> **tick**(): `unknown`

Starts the deliveries that fit in this tick's slice; the tick does not wait for them.

###### Returns

`unknown`

##### getChunkSendBudgetMs()

> **getChunkSendBudgetMs**(): `number`

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

This tick's chunk-send budget, read fresh each tick so config reloads apply.

###### Returns

`number`

##### getLogger()

> **getLogger**(): `object`

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

Where the catch-up skip warns and the lag profile prints.

###### Returns

`object`

###### error()

> **error**(`error`): `void`

###### Parameters

###### error

`unknown`

###### Returns

`void`

###### verbose()

> **verbose**(`message`, `scope?`): `void`

###### Parameters

###### message

`string`

###### scope?

`string`

###### Returns

`void`

###### warn()

> **warn**(`message`, `scope?`): `void`

###### Parameters

###### message

`string`

###### scope?

`string`

###### Returns

`void`

##### getProfileOwner()

> **getProfileOwner**(): `object`

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

The object the opt-in profiler was attached to (the server).

###### Returns

`object`

##### getWorlds()

> **getWorlds**(): [`TickerWorld`](#tickerworld)[]

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

The worlds to update this tick, in the order the ticker updates them, one after another.

###### Returns

[`TickerWorld`](#tickerworld)[]

##### isHeadless()

> **isHeadless**(): `boolean`

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

Headless servers do not own the terminal, so they leave the title alone.

###### Returns

`boolean`

##### isProcessTitleEnabled()

> **isProcessTitleEnabled**(): `boolean`

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

Whether to write TPS and tick into the process title.

###### Returns

`boolean`

##### isStopping()

> **isStopping**(): `boolean`

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

Whether a server shutdown has begun; a tick in flight then stops rescheduling.

###### Returns

`boolean`

##### isTickingEnabled()

> **isTickingEnabled**(): `boolean`

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

Whether the loop should run at all. Read once per `start()`.

###### Returns

`boolean`

##### pollNetwork()

> **pollNetwork**(): `number`

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

Delivers pending network records at this tick's fixed game-thread boundary.

###### Returns

`number`

##### tickFunctions()

> **tickFunctions**(): `number`

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

Runs `#minecraft:tick` and whatever `/schedule` put on this tick, as the input step's last
input, and returns how many command lines ran. The ticker does not wait for it, so an
asynchronous one does not satisfy this.

###### Returns

`number`

***

### TickerWorld

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

One world as the tick loop sees it: a name for the lag profile, and an update that runs to its end.

#### Methods

##### beginChangeTick()?

> `optional` **beginChangeTick**(): `void`

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

Opens the world's change log tick before the input step, so the inputs land in it.

###### Returns

`void`

##### closeTick()?

> `optional` **closeTick**(`tick`): `undefined`

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

Closes a tick the world did not update, such as a frozen one: seals the change log tick
opened before the input step and sends what the inputs did in it. It returns `undefined`
for the reason `update` does.

###### Parameters

###### tick

`number`

###### Returns

`undefined`

##### getName()

> **getName**(): `string`

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

###### Returns

`string`

##### update()

> **update**(`tick`): `undefined`

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

Runs the world's tick to its end. The ticker does not wait for it, so it returns
`undefined` and not `void`: an asynchronous method satisfies `void`, and its rejection would
go unhandled.

###### Parameters

###### tick

`number`

###### Returns

`undefined`

## Variables

### DEFAULT\_TICK\_RATE

> `const` **DEFAULT\_TICK\_RATE**: `20` = `20`

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

The tick rate a server runs at until `/tick rate` changes it.

***

### TPS\_AVERAGE\_MINUTES

> `const` **TPS\_AVERAGE\_MINUTES**: readonly \[`1`, `5`, `15`\]

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

The windows of the long TPS averages, in minutes, as Spigot's `/tps` reports them.

## Functions

### tickerModule()

> **tickerModule**(`ticker`): [`Module`](https://jsprismarine.dev/api/@jsprismarine/kernel/index.md#module)

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

Runs the [ServerTicker](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/classes/ServerTicker.md) as `prismarine:ticker`, providing it under
[tickerToken](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/tokens/index.md#tickertoken). The loop starts when the module starts and stops when it
stops; the server also stops it directly at the top of a shutdown, before any
teardown awaits, so no tick lands in a world mid-teardown.

#### Parameters

##### ticker

[`ServerTicker`](https://jsprismarine.dev/api/@jsprismarine/prismarine/modules/ticker/classes/ServerTicker.md)

The ticker the server constructed, so its counters are
readable before the kernel starts.

#### Returns

[`Module`](https://jsprismarine.dev/api/@jsprismarine/kernel/index.md#module)

The module to register on the kernel.
