Skip to main content

ServiceStream

Trait ServiceStream 

Source
pub trait ServiceStream: Send {
    // Required methods
    fn changed<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn snapshot<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Value> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A live push stream a service exposes for a subscription op.

See DaemonService::subscribe. The server owns the drive loop: it awaits changed (alongside its own periodic tick, so purely on-disk state changes are still caught), then calls snapshot and pushes the payload only when it differs from the last one sent — so the implementation never has to schedule, diff, or write anything itself (#1267).

Required Methods§

Source

fn changed<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Resolves when the service’s visible state may have changed since the previous call. Collapsing a burst of changes into one wakeup (coalescing) is the implementation’s job; a spurious wakeup is harmless because the server diffs the resulting snapshot. It must not resolve in a tight loop when there is nothing to report (e.g. once the change source is gone, park rather than return repeatedly), or it would spin the server’s select!.

Source

fn snapshot<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Value> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

The current snapshot payload, sent verbatim as DaemonReply::ok. May perform blocking work (offloaded to a blocking thread); the server awaits it between wakeups.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§