pub struct Subscription { /* private fields */ }Expand description
Controls a registered callback subscription.
Dropping this handle unsubscribes immediately and without waiting for a
callback worker. Use Subscription::close when the caller must await the
retirement of an already running callback and observe any callback fault.
Implementations§
Source§impl Subscription
impl Subscription
Sourcepub fn id(&self) -> SubscriptionId
pub fn id(&self) -> SubscriptionId
Return the identifier of the controlled subscription.
Sourcepub fn unsubscribe(&self) -> bool
pub fn unsubscribe(&self) -> bool
Prevent future deliveries and release the subscription’s capacity.
This operation is synchronous and idempotent. It does not wait for a callback that is already running to finish.
Sourcepub async fn close(self) -> Result<()>
pub async fn close(self) -> Result<()>
Unsubscribe and wait for callback execution to retire.
When awaited outside subscription callbacks, the returned error preserves a callback panic or dispatch failure. A successful result means the callback is no longer running; it does not imply that a previously delivered callback completed application work after returning control to the SDK.
Polling this future on a thread currently executing any synchronous
subscription callback first unsubscribes, then returns
ErrorKind::InvalidInput with field subscription.close and stage
crate::error::ErrorStage::Dispatch. This also applies when closing a
different or already idle subscription, to prevent callbacks from waiting
for each other. This error does not guarantee that the callback has retired.
Use CallbackContext::unsubscribe inside a callback and retain the
subscription handle outside it when retirement must be awaited.
The check runs on every poll, not when the future is created. A future created in a callback can be awaited outside it after the callback returns. The check only sees the current thread’s subscription callback stack; do not wait in a callback for another thread or task that is closing it. Cancelling this future does not reactivate the subscription or interrupt an already running callback.