Skip to main content

SubscriptionBuilder

Struct SubscriptionBuilder 

Source
pub struct SubscriptionBuilder<S, P, SS>{ /* private fields */ }
Expand description

Builder for configuring and starting a subscription.

Created via Repository::subscribe(). Use on_update() to register callbacks, then call start() to begin processing events.

Implementations§

Source§

impl<S, P, SS> SubscriptionBuilder<S, P, SS>
where S: SubscribableStore + Clone + Send + Sync + 'static, S::Position: Ord + Send + Sync, S::Data: Send, S::Metadata: Send + Sync, P: Projection + ProjectionFilters<Id = S::Id, Metadata = S::Metadata> + Serialize + DeserializeOwned + Send + Sync + 'static, P::InstanceId: Clone + Send + Sync + 'static, P::Metadata: Send, SS: SnapshotStore<P::InstanceId, Position = S::Position> + Send + Sync + 'static,

Source

pub fn on_update<F>(self, callback: F) -> Self
where F: Fn(&P) + Send + Sync + 'static,

Register a callback invoked after each event is applied.

Callbacks must complete quickly. Long-running work should be dispatched to a separate task via a channel. Blocking the callback stalls the subscription loop and delays event processing.

Source

pub async fn start( self, ) -> Result<SubscriptionHandle<S::Error>, SubscriptionError<S::Error>>

Start the subscription.

This method returns only after catch-up completes.

Spawns a background task that:

  1. Loads the most recent snapshot (if available)
  2. Subscribes to the event stream from the snapshot position
  3. Replays historical events (catch-up phase)
  4. Waits until catch-up is complete
  5. Continues processing live events and firing on_update
§Errors

Returns an error if the initial snapshot load or stream setup fails.

Auto Trait Implementations§

§

impl<S, P, SS> Freeze for SubscriptionBuilder<S, P, SS>

§

impl<S, P, SS> !RefUnwindSafe for SubscriptionBuilder<S, P, SS>

§

impl<S, P, SS> Send for SubscriptionBuilder<S, P, SS>
where SS: Send, <P as ProjectionFilters>::InstanceId: Send,

§

impl<S, P, SS> Sync for SubscriptionBuilder<S, P, SS>
where SS: Sync, <P as ProjectionFilters>::InstanceId: Sync,

§

impl<S, P, SS> Unpin for SubscriptionBuilder<S, P, SS>
where S: Unpin, SS: Unpin, <P as ProjectionFilters>::InstanceId: Unpin,

§

impl<S, P, SS> !UnwindSafe for SubscriptionBuilder<S, P, SS>

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