EventBus
Internal event bus that buffers StreamEvents and exposes them
as an AsyncIterable.
Used by AgentRun to bridge between the synchronous agent loop
(which emits events) and the asynchronous consumer (which iterates).
Events are buffered in memory. If a consumer is already waiting,
it is unblocked immediately. When close() is called, the iterator
drains remaining buffered events and then returns.
Single-consumer only. Each AgentRun has its own bus, designed for one async iterator consumer at a time. Multiple consumers will miss events.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new EventBus():
EventBus
Returns
Section titled “Returns”EventBus
Methods
Section titled “Methods”[asyncIterator]()
Section titled “[asyncIterator]()”[asyncIterator]():
AsyncIterator<StreamEvent>
Async iterator that yields buffered events as they arrive. Waits when the buffer is empty and the bus is still open. Returns when the bus is closed and all events have been yielded.
Consumed events are cleared from the buffer to prevent unbounded memory growth in long-running sessions.
Returns
Section titled “Returns”AsyncIterator<StreamEvent>
close()
Section titled “close()”close():
void
Signal that no more events will be emitted. The async iterator will drain any remaining buffered events and then finish.
Returns
Section titled “Returns”void
emit()
Section titled “emit()”emit(
event):void
Emit an event. If a consumer is waiting, unblock it immediately.
Events emitted after close() are silently ignored.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void