Skip to main content

Subscription

Struct Subscription 

Source
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§

Source§

impl Subscription

Source

pub fn path(&self) -> &Path

Returns the path this subscription resolves.

Source

pub fn origin(&self) -> Consumer

Returns the route table the path was resolved in.

Source

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.

Source

pub fn value_track<T: DeserializeOwned>( &self, name: &str, ) -> Result<ValueReader<T>, Error>

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);
}
Source

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.

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.

Source

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§

Source§

impl Clone for Subscription

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Subscription

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more