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

# world/ChunkScheduler

## Classes

- [ChunkScheduler](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/ChunkScheduler/classes/ChunkScheduler.md)

## Interfaces

### ChunkRecipient

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:24](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L24)

What the scheduler needs of a player: a queue, and a way to deliver one chunk.

#### Properties

##### sender

> `readonly` **sender**: [`SchedulableSender`](#schedulablesender)

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:25](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L25)

#### Methods

##### admits()?

> `optional` **admits**(): `boolean`

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:43](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L43)

Whether the recipient takes another chunk this tick, for a client that paces its own; a
recipient that answers false is passed over as though its queue were empty.

###### Returns

`boolean`

##### deliver()

> **deliver**(`x`, `z`): `Promise`\<`void`\>

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:31](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L31)

Resolves once the chunk is on its way; rejects if it could not be produced.

###### Parameters

###### x

`number`

###### z

`number`

###### Returns

`Promise`\<`void`\>

##### flush()

> **flush**(): `Promise`\<`void`\>

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:34](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L34)

Dispatches whatever `deliver` produced but has not sent yet.

###### Returns

`Promise`\<`void`\>

##### isConnected()

> **isConnected**(): `boolean`

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:37](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L37)

Dropped from the rotation when this goes false.

###### Returns

`boolean`

##### paceTick()?

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

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:46](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L46)

Moves the recipient's own pace on by a tick, once each scheduler tick, joined or not.

###### Returns

`void`

##### tryDeliverLoaded()?

> `optional` **tryDeliverLoaded**(`x`, `z`): [`CachedChunkDelivery`](#cachedchunkdelivery)

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:28](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L28)

Queues an already-loaded chunk synchronously, or reports that generation is still needed.

###### Parameters

###### x

`number`

###### z

`number`

###### Returns

[`CachedChunkDelivery`](#cachedchunkdelivery)

***

### SchedulableSender

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:7](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L7)

A queue the scheduler can drain: one player's outstanding chunks.

#### Methods

##### enqueue()?

> `optional` **enqueue**(`x`, `z`): `void`

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:11](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L11)

Restores a coordinate when a loaded-chunk delivery cannot fit this connection's byte cap.

###### Parameters

###### x

`number`

###### z

`number`

###### Returns

`void`

##### isEmpty()

> **isEmpty**(): `boolean`

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:8](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L8)

###### Returns

`boolean`

##### next()

> **next**(): \{ `x`: `number`; `z`: `number`; \} \| `null`

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:9](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L9)

###### Returns

\{ `x`: `number`; `z`: `number`; \} \| `null`

## Type Aliases

### CachedChunkDelivery

> **CachedChunkDelivery** = \{ `kind`: `"queued"`; `queuedBytes`: `number`; \} \| \{ `inline?`: `boolean`; `kind`: `"not-loaded"`; \} \| \{ `kind`: `"backpressure"`; \}

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:20](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L20)

Whether a recipient could queue a loaded chunk without waiting for generation capacity.

`inline` on a chunk that is not loaded says its world's generator builds it on this thread
with no worker pool, so the delivery waits for the inline depth rather than the worker depth.

***

### ChunkFailureHandler

> **ChunkFailureHandler** = (`error`, `coord?`) => `void`

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:75](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L75)

Told about a chunk that could not be produced or sent. `coord` is absent when the failure
was a flush, which covers a whole batch rather than one coordinate.

#### Parameters

##### error

`unknown`

##### coord?

###### x

`number`

###### z

`number`

#### Returns

`void`

## Variables

### DEFAULT\_BUDGET\_MS

> `const` **DEFAULT\_BUDGET\_MS**: `5` = `5`

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:50](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L50)

How long a tick may spend starting chunk deliveries, out of the 50 ms a tick has.

***

### DEFAULT\_DEPTH

> `const` **DEFAULT\_DEPTH**: `number`

Defined in: [packages/prismarine/src/world/ChunkScheduler.ts:60](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/ChunkScheduler.ts#L60)

How many chunk requests the server may have in flight.

The generator has its own admission queue, sized to its worker count. Keeping a second set of
requests here lets it know upcoming player targets early enough to prioritize their status
tasks. A host without a worker still keeps two requests in flight; its generator serializes
the work itself.

***

### DEFAULT\_INLINE\_DEPTH

> `const` **DEFAULT\_INLINE\_DEPTH**: `64` = `CHUNK_ADMISSION_BUDGET_PER_TICK`

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

How many deliveries of chunks a generator builds inline may be in flight.

No worker pool waits behind them, so the worker depth does not apply. Each one waits for the
input step after its chunk is ready, and one step admits at most this many, so starting more
per tick would only lengthen the wait.

## References

### chunkScheduler

Renames and re-exports [ChunkScheduler](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/ChunkScheduler/classes/ChunkScheduler.md)
