pub struct OriginConsumer { /* private fields */ }Expand description
Consumes announced broadcasts matching against an optional prefix.
NOTE: Clone is expensive, try to avoid it.
Implementations§
Source§impl OriginConsumer
impl OriginConsumer
Sourcepub async fn announced(&mut self) -> Option<OriginAnnounce>
pub async fn announced(&mut self) -> Option<OriginAnnounce>
Returns the next (un)announced broadcast and the absolute path.
The broadcast will only be announced if it was previously unannounced. The same path won’t be announced/unannounced twice, instead it will toggle. Returns None if the consumer is closed.
Note: The returned path is absolute and will always match this consumer’s prefix.
Sourcepub fn try_announced(&mut self) -> Option<OriginAnnounce>
pub fn try_announced(&mut self) -> Option<OriginAnnounce>
Returns the next (un)announced broadcast and the absolute path without blocking.
Returns None if there is no update available; NOT because the consumer is closed.
You have to use is_closed to check if the consumer is closed.
Sourcepub fn consume(&self) -> Self
pub fn consume(&self) -> Self
Create another consumer with its own announcement cursor over the same origin.
Sourcepub fn get_broadcast(&self, path: impl AsPath) -> Option<BroadcastConsumer>
pub fn get_broadcast(&self, path: impl AsPath) -> Option<BroadcastConsumer>
Get a broadcast by path if it has already been announced.
Returns None when the path is unknown to this consumer right now. Synchronous
lookup races announcement gossip — a freshly-connected consumer will see None
even when the broadcast is about to arrive. Prefer Self::announced_broadcast
(blocks until announced) unless you can guarantee the announcement has already
landed (e.g. you’re responding to an announced() callback).
Sourcepub async fn announced_broadcast(
&self,
path: impl AsPath,
) -> Option<BroadcastConsumer>
pub async fn announced_broadcast( &self, path: impl AsPath, ) -> Option<BroadcastConsumer>
Block until a broadcast with the given path is announced and return it.
Returns None if the path is outside this consumer’s allowed prefixes or if the consumer
is closed before the broadcast is announced. The returned broadcast may itself be closed
later — subscribers should watch BroadcastConsumer::closed to react to that.
Prefer this over Self::get_broadcast when you know the exact path you want but
cannot guarantee the announcement has already been received.
Sourcepub fn scope(&self, prefixes: &[Path<'_>]) -> Option<OriginConsumer>
pub fn scope(&self, prefixes: &[Path<'_>]) -> Option<OriginConsumer>
Returns a new OriginConsumer restricted to broadcasts under one of prefixes.
Returns None if there are no legal prefixes (the requested prefixes are disjoint from this consumer’s current scope, so it would always return None).
Sourcepub fn with_root(&self, prefix: impl AsPath) -> Option<Self>
pub fn with_root(&self, prefix: impl AsPath) -> Option<Self>
Returns a new OriginConsumer that automatically strips out the provided prefix.
Returns None if the provided root is not authorized; when Self::scope was
already used without a wildcard.
Sourcepub fn root(&self) -> &Path<'_>
pub fn root(&self) -> &Path<'_>
Returns the prefix that is automatically stripped from all paths.