pub struct TensorEventBusV2 {
pub subscriptions: Vec<Subscription>,
pub dead_letters: Vec<TensorEvent>,
pub stats: BusStats,
pub next_sub_id: u64,
}Expand description
Typed in-process event bus for TensorLogic events.
Events are published synchronously and fanned out to all matching subscriptions in descending priority order. Each subscription maintains a bounded queue; events that overflow the queue are counted as dropped. Events that match no subscription are collected in the dead-letter queue.
Fields§
§subscriptions: Vec<Subscription>Active subscriptions, kept sorted by priority descending.
dead_letters: Vec<TensorEvent>Events that were not delivered to any subscriber.
stats: BusStatsBus-level statistics.
next_sub_id: u64Monotonically increasing counter used to assign subscription IDs.
Implementations§
Source§impl TensorEventBusV2
impl TensorEventBusV2
Sourcepub fn subscribe(
&mut self,
filter: EventFilter,
priority: u32,
max_queue_size: usize,
) -> u64
pub fn subscribe( &mut self, filter: EventFilter, priority: u32, max_queue_size: usize, ) -> u64
Registers a new subscription and returns its unique identifier.
The internal subscription list is re-sorted after each registration so that
publish can iterate in priority order without extra work.
Sourcepub fn unsubscribe(&mut self, sub_id: u64) -> bool
pub fn unsubscribe(&mut self, sub_id: u64) -> bool
Removes the subscription identified by sub_id.
Returns true if the subscription existed and was removed.
Sourcepub fn publish(&mut self, event: TensorEvent)
pub fn publish(&mut self, event: TensorEvent)
Publishes an event to all matching subscriptions.
Subscriptions are visited in descending priority order. For each subscription whose filter matches:
- If the queue is not full, the event is cloned and enqueued;
deliveredandstats.total_deliveredare incremented. - If the queue is full, the event is not enqueued;
droppedandstats.total_droppedare incremented.
If no subscription accepted the event it is moved to dead_letters.
Sourcepub fn drain(&mut self, sub_id: u64) -> Vec<TensorEvent>
pub fn drain(&mut self, sub_id: u64) -> Vec<TensorEvent>
Drains and returns all queued events for the subscription identified by sub_id.
Returns an empty Vec if the subscription does not exist or has no pending events.
Trait Implementations§
Source§impl Debug for TensorEventBusV2
impl Debug for TensorEventBusV2
Auto Trait Implementations§
impl Freeze for TensorEventBusV2
impl RefUnwindSafe for TensorEventBusV2
impl Send for TensorEventBusV2
impl Sync for TensorEventBusV2
impl Unpin for TensorEventBusV2
impl UnsafeUnpin for TensorEventBusV2
impl UnwindSafe for TensorEventBusV2
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more