Struct Subscription
pub struct Subscription { /* private fields */ }Expand description
A path resolved in a route table.
moq moves the broadcast between routes of one identity without ending it.
When another identity takes the path over, broadcast
switches to what serves it now. moq-lite-06 names no identity on the wire,
so each session mints its own: a move between a direct link and a media relay is
such a switch, and readers of the old broadcast start over on the new. Cheap
to clone. For media, iroh_live::media::SubscriptionExt::remote_broadcast reads it
as a RemoteBroadcast that adapts to the serving link.
§Examples
use iroh_live_node::Reach;
let subscription = node.subscribe("live/camera", Reach::Both(peer)).await?;
let broadcast = subscription.broadcast();
// Resolves once no route serves the path any more.
subscription.closed().await;Implementations§
§impl Subscription
impl Subscription
pub fn broadcast(&self) -> Consumer
pub fn broadcast(&self) -> Consumer
Returns the broadcast that serves the path now.
A later call may return a newer broadcast than an earlier one. For
media, iroh_live::media::SubscriptionExt::remote_broadcast reads it
as a RemoteBroadcast that adapts to the serving link.
pub fn value_track<T>(&self, name: &str) -> Result<ValueReader<T>, Error>where
T: DeserializeOwned,
pub fn value_track<T>(&self, name: &str) -> Result<ValueReader<T>, Error>where
T: DeserializeOwned,
Returns a reader of the latest-value JSON track name of the broadcast.
The publisher writes it with Node::publish_value or a
ValueWriter of its own. Each value carries the
time it was published in Timed::at. The reader skips to the newest
value with latest, and a late reader gets the
current value at once. The reader follows the subscription: when the
publisher restarts, it reads the track of the new broadcast, and it
ends only once the subscription closes. For a reader of one broadcast
with other limits, pass broadcast().track(name)
to json::snapshot::Consumer::new with a config of its own.
§Errors
Fails with [Error::Moq] when the broadcast has ended, or when a local
broadcast has no track name. A remote publisher answers for its
tracks itself, so there a missing track fails the first read instead.
§Examples
let mut latency = subscription.value_track::<u64>("latency")?;
while let Some(newest) = latency.latest().await? {
println!("latency {} ms", newest.value);
}pub fn session(&self) -> Option<Session>
pub fn session(&self) -> Option<Session>
Returns the session serving the broadcast now, if a direct session does.
The session gives the iroh connection with its paths
(Session::connection) and the latest reading of the link
(Session::sample). Asking the subscription each time, rather than
keeping a session from an earlier dial, follows the subscription when
another link takes over. None while a media relay serves the broadcast.
pub fn serving_link(&self) -> Option<ServingLink>
pub fn serving_link(&self) -> Option<ServingLink>
Returns the link serving the broadcast now, and its latest reading.
None before the table announces a route, for a publication of this
node, and once the serving link is gone. Also None when a media relay
serves the route and several media relays feed the table, since a media relay’s
route does not say which media relay it came from.
For the iroh connection and its paths, use session.
pub async fn closed(&self)
pub async fn closed(&self)
Waits until nothing serves the path.
A pinned subscription never moves to another identity, and ends once its own no longer serves the path. Cancellation safe.
Trait Implementations§
§impl Clone for Subscription
impl Clone for Subscription
§fn clone(&self) -> Subscription
fn clone(&self) -> Subscription
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more