RingBuffer<T>

class
ring-buffer.ts:20

Fixed-size circular buffer that overwrites the oldest entry on overflow.

Used by the hub to retain event history for late-connecting extensions. The buffer pre-allocates an array of the given capacity and uses modular arithmetic to track insertion position, making push an O(1) operation with no memory allocation after construction.

Type parameters

NameTypeDescription
T–Item type stored in the buffer.

Constructor

constructor

signature
new<T>(capacity): RingBuffer<T>

Type parameters

NameTypeDescription
T–

Parameters

NameTypeDescription
capacitynumberMaximum number of items. Must be at least 1.

Returns

RingBuffer<T>

Properties

NameTypeDescription
capacitynumberMaximum number of items. Must be at least 1.
sizeget/setnumber

Methods

clear

Remove all items.

signature
clear(): void

Remove all items.

Returns

void

push

Push an item. Overwrites the oldest if at capacity.

signature
push(item): void

Push an item. Overwrites the oldest if at capacity.

Parameters

NameTypeDescription
itemTItem to add.

Returns

void

toArray

Returns all items in insertion order (oldest first).

signature
toArray(): T[]

Returns all items in insertion order (oldest first).

Returns

T[], A new array containing buffered items from oldest to newest.