Skip to main content

Module live

Module live 

Source
Expand description

Live views of a shared value.

channel creates a LivePublisher and a LiveSource that share one root value. The publisher replaces the root and notifies views. The source reads the root and creates Live views of parts of it. Each view caches a snapshot of its selected value and refreshes it only when Live::changed processes a notification.

use saluki_common::sync::live;

struct Root {
    enabled: bool,
}

let (mut publisher, source) = live::channel(Root { enabled: false });
let mut enabled = source.live(|root| &root.enabled);
publisher.publish(Root { enabled: true });

// An existing view keeps its snapshot until `changed` processes the update; a new view reads the latest root.
assert!(!*enabled);
assert!(*source.live(|root| &root.enabled));

assert!(enabled.changed().await);
assert!(*enabled);

Structs§

Live
A typed view of one projection of a shared value.
LivePublisher
The handle that replaces a channel’s root value.
LiveSource
A read-only handle to a channel’s root value, used to load it and to create views of it.

Functions§

channel
Creates a publisher and a source that share initial as their root value.