Struct EventWriter<T>
A producer's handle on one worker slot of an EventQueue<T> (#861). Resolve it once per system body, then push through it.
public ref struct EventWriter<T>
Type Parameters
TThe event type.
- Inherited Members
Remarks
The point of the type is that the slot lookup happens ONCE. After that, Push(T) is a bounds check, an array store and two increments
against fields this thread exclusively owns — no Interlocked, no shared cache line, no indirection back through the queue. That is what keeps
a multi-producer queue at single-producer cost.
Stack-only and single-threaded by construction. A ref struct cannot be captured into a lambda, boxed, or stored on the heap, so a
writer cannot outlive its system body or be smuggled onto another thread — the compiler enforces the invariant the design depends on.
Obtain one with ctx.Writer(queue), which supplies the caller's WorkerId.
Properties
Count
Events accepted into this slot so far this tick. Zero for an invalid writer.
public readonly int Count { get; }
Property Value
IsValid
False for a default writer — one built from a null queue. Pushing through it is a no-op.
public readonly bool IsValid { get; }
Property Value
Methods
Push(T)
Appends an event to this worker's segment.
public bool Push(T item)
Parameters
itemTThe event to enqueue.
Returns
- bool
trueif the event was stored;falseif it was dropped because the segment is at its growth ceiling. A dropped event is counted in OverflowCount.Pushdeliberately never throws: it runs inside parallel chunks, where an exception is converted into a system failure and, under a strict tick-abort policy (#567), can cancel the rest of the tick.