pub struct Subscription<T, E = String> { /* private fields */ }Expand description
A handle that observes one product’s configuration as the client publishes it.
T is the snapshot the product’s ProductDecoder builds and E is the error it produces,
so a subscription reads as the value it delivers rather than as the decoder that produced it. A product with nothing
richer to report leaves E at its default of String.
A consumer reads current and then loops on changed. A subscription created
after the client has already published treats that value as observed and receives no notification for it, so a
consumer that only awaited changed would wait for a snapshot that may never arrive.
Cloning shares one subscription between several consumers: each clone tracks its own position, while decoding happens once per snapshot. Slow consumers may skip intermediate publications and observe only the latest state. Dropping the last clone unsubscribes the product.
Implementations§
Source§impl<T, E> Subscription<T, E>
impl<T, E> Subscription<T, E>
Sourcepub fn inert() -> Self
pub fn inert() -> Self
Creates a subscription that never receives a snapshot.
Use this where a component takes a subscription but the process has no client to subscribe with, for example
because Remote Configuration is turned off. The component then runs the same code path as one whose client has
not delivered anything yet: current always returns None, and changed
waits indefinitely.
An inert subscription is not registered with any client, so it does not count against a client’s one subscription per product.
Sourcepub fn current(&self) -> Option<Arc<T>>
pub fn current(&self) -> Option<Arc<T>>
Returns the most recently accepted configuration.
Returns None until the first snapshot is accepted, whether because the worker has not yet polled, is not
running, or the subscription is inert. None does not mean the product has no configuration
assigned: a fresh decoder’s build must produce a snapshot even for an empty
assignment.
Sourcepub async fn changed(&mut self) -> Result<Arc<T>, Arc<E>>
pub async fn changed(&mut self) -> Result<Arc<T>, Arc<E>>
Waits for a newly published snapshot.
This takes &mut self because the subscription tracks which publication it has observed. Each task that waits
holds its own clone.
Slow consumers may skip intermediate publications and observe only the latest state. Once the worker stops,
this waits indefinitely after any pending publication has been observed, so a caller may select! on it.
A published snapshot is not guaranteed to differ from the previous one: after the worker restarts, it decodes every product again.
§Errors
Returns the subscriber’s own decoding error when the snapshot was rejected. The client reports that rejection to
the Agent independently; a consumer with nothing to report can ignore it. current continues
to return the last accepted configuration.
Trait Implementations§
Source§impl<T, E> Clone for Subscription<T, E>
impl<T, E> Clone for Subscription<T, E>
Auto Trait Implementations§
impl<T, E> Freeze for Subscription<T, E>
impl<T, E> RefUnwindSafe for Subscription<T, E>
impl<T, E> Send for Subscription<T, E>
impl<T, E> Sync for Subscription<T, E>
impl<T, E> Unpin for Subscription<T, E>
impl<T, E> UnwindSafe for Subscription<T, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Track for T
impl<T> Track for T
Source§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
Tracked wrapper. Read moreSource§fn in_current_resource_group(self) -> Tracked<Self>
fn in_current_resource_group(self) -> Tracked<Self>
Tracked wrapper. Read more