pub struct EventRegistry { /* private fields */ }Expand description
Thread-safe registration and dispatch container for lifecycle callbacks.
Dispatch clones one Arc snapshot without allocating and releases the lock
before invoking callbacks. A dispatch already in progress may finish with
its original snapshot; registration and removal affect future dispatches.
Nested dispatch observes the current snapshot at the time it starts.
Implementations§
Source§impl EventRegistry
impl EventRegistry
Sourcepub fn on_event<F>(&self, handler: F) -> Result<(), EventRegistrationError>
pub fn on_event<F>(&self, handler: F) -> Result<(), EventRegistrationError>
Register a callback that remains installed until the registry closes.
§Errors
Returns EventRegistrationError when the registry reached its handler
cap, has closed, or its state is unavailable after a callback panic.
Sourcepub fn subscribe<F>(
&self,
handler: F,
) -> Result<EventSubscription, EventRegistrationError>
pub fn subscribe<F>( &self, handler: F, ) -> Result<EventSubscription, EventRegistrationError>
Register a callback removed automatically when its subscription drops.
§Errors
Returns EventRegistrationError when the registry reached its handler
cap, has closed, or its state is unavailable after a callback panic.
Sourcepub fn dispatch(&self, event: &DesktopEvent) -> EventResponse
pub fn dispatch(&self, event: &DesktopEvent) -> EventResponse
Dispatch an event and report cancellation.
Every handler in the dispatch snapshot observes the event even after one cancels it, so the outcome does not depend on registration order.