Skip to main content

EventSource

Trait EventSource 

Source
pub trait EventSource: 'static {
    type Origin: Clone + 'static;
    type Event: Send + 'static;

    // Required method
    fn subscribe(
        &self,
        origin: Self::Origin,
        callback: Arc<dyn Fn(Self::Event) + Send + Sync + 'static>,
    ) -> SubscriptionHandle;
}
Expand description

An external source of events that widgets can subscribe to.

Implementations include backend message buses, database change notifiers, file watchers, network response channels — any source that publishes events asynchronously and that widgets need to react to.

Required Associated Types§

Source

type Origin: Clone + 'static

The key by which subscribers identify which events they care about. Typically an enum (a Qleany Origin) or a topic string.

Source

type Event: Send + 'static

The event payload delivered to subscriber callbacks. Must be Send because events cross from the publisher’s thread to the UI thread via the framework’s proxy bridge.

Required Methods§

Source

fn subscribe( &self, origin: Self::Origin, callback: Arc<dyn Fn(Self::Event) + Send + Sync + 'static>, ) -> SubscriptionHandle

Subscribe a callback to events of a given origin. The callback is invoked on whatever thread the source publishes from (typically a background thread). The returned handle, when dropped, removes the subscription from the source’s internal registry.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§