Struct wnf::Subscription
source · pub struct Subscription<'a, F> { /* private fields */ }
subscribe
only.Expand description
A subscription of a listener to updates of a state
This is returned from OwnedState::subscribe
and BorrowedState::subscribe
.
Note that the listener is automatically unsubscribed when the Subscription<'_, F>
is dropped. In
this case, errors while unsubscribing are silently ignored. If you want to handle them explicitly, use the
Subscription::unsubscribe
method, which returns an io::Result<()>
. Note that the listener will
not be called anymore after unsubscribing, even when there is an error.
If you want to keep the subscription for as long as the process is running and the state exists, use the
Subscription::forget
method.
Implementations§
source§impl<F> Subscription<'_, F>
impl<F> Subscription<'_, F>
sourcepub const fn forget(self)
pub const fn forget(self)
Forgets this Subscription<'_, F>
, effectively keeping it forever
When a Subscription<'_, F>
is dropped, the listener is unsubscribed. You can avoid this
behavior by calling this method. It consumes the Subscription<'_, F>
without dropping it,
effectively keeping the subscription for as long as the process is running and the state exists.
sourcepub fn unsubscribe(self) -> Result<()>
pub fn unsubscribe(self) -> Result<()>
Unsubscribes the listener for this Subscription<'_, F>
This happens automatically when the Subscription<'_, F>
is dropped (unless you call
Subscription::forget
), so there is usually no need to call this method. Its only purpose is to enable you
to handle errors while unsubscribing. Note that the listener will not be called anymore after unsubscribing,
even when there is an error.
Errors
Returns an error if unsubscribing fails