pub struct Subscription<T> { /* private fields */ }Expand description
A typed subscription to a Relay.
Receives messages of type T from the stream.
Type filtering happens locally - wrong types are skipped, not errored.
§Observable Delivery
Subscriptions receive messages via try_send with buffering (default: 65536).
If a subscriber’s buffer fills, messages are dropped and observable via Dropped events.
No backpressure - senders never block waiting for slow consumers.
§Completion Semantics
There are two kinds of subscriptions:
- Tracked (used by sink/tap): Participates in completion tracking. Signals completion for wrong-type messages, fails tracker on Drop.
- Untracked (from
subscribe()): Does NOT participate in tracking. Still receives all messages, but sender doesn’t wait for completion.
Tracked subscriptions are created internally by sink/tap handlers.
Raw subscriptions from subscribe() are untracked.
Implementations§
Source§impl<T: 'static + Send + Sync> Subscription<T>
impl<T: 'static + Send + Sync> Subscription<T>
Sourcepub fn current_tracker(&self) -> Option<Arc<CompletionTracker>>
pub fn current_tracker(&self) -> Option<Arc<CompletionTracker>>
Get the completion tracker for the current message.
Returns None if no message is being processed or if the message
was sent without completion tracking (fire-and-forget).
Handlers should call tracker.complete_one() on success or
tracker.fail(error) on failure.
Sourcepub fn current_msg_id(&self) -> Option<u64>
pub fn current_msg_id(&self) -> Option<u64>
Get the message ID of the current message being processed.
Returns None if no message is being processed.
Sourcepub fn clear_tracker(&mut self)
pub fn clear_tracker(&mut self)
Clear the current tracker without signaling completion.
Called by handlers after they’ve explicitly completed the tracker. This prevents double-completion and ensures Drop doesn’t fail an already-completed message.
Sourcepub async fn recv(&mut self) -> Option<Arc<T>>
pub async fn recv(&mut self) -> Option<Arc<T>>
Receive the next message of type T.
Returns None when the stream is closed.
Messages of other types are skipped automatically.
Important: Handlers must call complete_one() or fail() on the
tracker before calling recv() again. This method does NOT auto-complete
for messages of the matching type.
Sourcepub fn try_recv(&mut self) -> Option<Arc<T>>
pub fn try_recv(&mut self) -> Option<Arc<T>>
Try to receive a message without waiting.
Returns None if no message is available or the stream is closed.
Important: Handlers must call complete_one() or fail() on the
tracker before calling try_recv() again. This method does NOT auto-complete
for messages of the matching type.