pub struct NotificationBus { /* private fields */ }Expand description
Publish/subscribe bus for JobEvents.
Built on a tokio::sync::broadcast channel; all subscribers receive every
event. Lagged subscribers (that fall more than capacity events behind) will
receive a broadcast::error::RecvError::Lagged error and must re-subscribe
if they need to continue receiving.
Implementations§
Source§impl NotificationBus
impl NotificationBus
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new bus with the given ring-buffer capacity.
A reasonable default is 64–256 events. When the buffer fills, the oldest
events are dropped and late subscribers receive a Lagged error.
Sourcepub fn send(&self, event: JobEvent) -> usize
pub fn send(&self, event: JobEvent) -> usize
Publish an event to all current subscribers.
Returns the number of active receivers that received the event. Returns 0 if no subscribers are active (not an error).
Sourcepub fn subscribe(&self) -> Receiver<JobEvent>
pub fn subscribe(&self) -> Receiver<JobEvent>
Subscribe to future events.
The returned receiver will receive all events published after this call. Clone the receiver to fan it out to multiple async tasks.
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Returns the number of active subscribers.
Sourcepub fn notify(&self, job_id: Uuid, event_type: JobEventType) -> usize
pub fn notify(&self, job_id: Uuid, event_type: JobEventType) -> usize
Create a convenience event and send it in one call.
Trait Implementations§
Source§impl Debug for NotificationBus
impl Debug for NotificationBus
Auto Trait Implementations§
impl !RefUnwindSafe for NotificationBus
impl !UnwindSafe for NotificationBus
impl Freeze for NotificationBus
impl Send for NotificationBus
impl Sync for NotificationBus
impl Unpin for NotificationBus
impl UnsafeUnpin for NotificationBus
Blanket Implementations§
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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request