Skip to main content

Subscription

Struct Subscription 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T> Debug for Subscription<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for Subscription<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Subscription<T>

§

impl<T> !RefUnwindSafe for Subscription<T>

§

impl<T> Send for Subscription<T>
where T: Send,

§

impl<T> Sync for Subscription<T>
where T: Sync,

§

impl<T> Unpin for Subscription<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Subscription<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more