pub struct EventBus { /* private fields */ }Expand description
Event bus
Asynchronously handles events of arbitrary Any type by passing them in-order to a set of registered async ‘handler’ functions. Handlers are processes in an unordered fashion, but an event is fully handled by all handlers until the next event in the posted event stream is processed.
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub async fn startup(&self) -> Result<(), StartupLockAlreadyStartedError>
pub async fn startup(&self) -> Result<(), StartupLockAlreadyStartedError>
Start up the EventBus background processor
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Shut down EventBus background processing This unregisters all handlers as well and discards any unprocessed events
Sourcepub fn post<E: Any + Send + Sync + 'static>(
&self,
evt: E,
) -> Result<(), StartupLockNotStartedError>
pub fn post<E: Any + Send + Sync + 'static>( &self, evt: E, ) -> Result<(), StartupLockNotStartedError>
Post an event to be processed
Sourcepub fn subscribe<E: Any + Send + Sync + 'static, F: Fn(Arc<E>) -> SendPinBoxFuture<()> + Send + Sync + 'static>(
&self,
handler: F,
) -> EventBusSubscription
pub fn subscribe<E: Any + Send + Sync + 'static, F: Fn(Arc<E>) -> SendPinBoxFuture<()> + Send + Sync + 'static>( &self, handler: F, ) -> EventBusSubscription
Subscribe a handler to handle all posted events of a particular type Returns an subscription object that can be used to cancel this specific subscription if desired
Sourcepub fn unsubscribe(&self, sub: EventBusSubscription)
pub fn unsubscribe(&self, sub: EventBusSubscription)
Given a subscription object returned from subscribe, removes the
subscription for the EventBus. The handler will no longer be called.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EventBus
impl !RefUnwindSafe for EventBus
impl Send for EventBus
impl Sync for EventBus
impl Unpin for EventBus
impl !UnwindSafe for EventBus
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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