Skip to main content

PreparedSession

Struct PreparedSession 

Source
pub struct PreparedSession { /* private fields */ }
Expand description

A session that has been configured but not yet created on the CLI.

Returned by Client::prepare_session and Client::prepare_resume_session. Its purpose is to make the session’s event stream observable before any protocol activity starts: subscribe installs a receiver on the same broadcast channel the eventual Session uses, so events the runtime emits while session.create / session.resume is still in flight are delivered rather than dropped for lack of a receiver.

§Lifecycle

A prepared handle is inert. It holds only a broadcast sender, a cancellation token, the client handle, and the config — it performs no router registration, spawns no task, and writes nothing to the wire until start is first polled.

  • Dropping it without starting leaves no client-side or server-side state, and closes every subscription taken from it.
  • Dropping the start future mid-flight cancels the session token, unregisters the session from the router if it was registered, and closes early subscriptions. A retry with the same session ID succeeds. Cleanup of already-spawned tasks is signalled, not awaited: Drop is synchronous and cannot await, so the event loop terminates promptly but not synchronously.
  • A startup error from start performs the same cleanup and preserves the ErrorKind the equivalent Client::create_session / Client::resume_session call has always returned.

start consumes self and the type is deliberately not Clone, so a prepared session can be started at most once and can never produce two event loops.

§Buffering

The broadcast buffer is finite — DEFAULT_EVENT_BUFFER_CAPACITY unless SessionConfig::event_buffer_capacity / ResumeSessionConfig::event_buffer_capacity overrides it. Subscribers that fall behind observe Lagged instead of applying backpressure to the event loop. Consumers that need a lossless view of a large startup burst must either configure a capacity that covers it or drain the subscription concurrently with start.

§Server-assigned session IDs

For cloud sessions without a caller-supplied session ID, the CLI assigns the ID and the SDK can only register the session on its notification router once the session.create response arrives. Notifications the server emits before that point are not routable to any session and are therefore not observable. The guarantee this type provides is narrower and precise: routed events are never dropped for lack of an installed receiver. Pin SessionConfig::session_id to get registration before the RPC and full pre-response coverage.

Implementations§

Source§

impl PreparedSession

Source

pub fn subscribe(&self) -> EventSubscription

Subscribe to this session’s events before it starts.

The returned EventSubscription is backed by the same broadcast channel Session::subscribe returns after start succeeds, so a subscription taken here observes the full event stream from the session’s first routed event onward — including ephemeral events such as session.idle that Session::get_messages cannot recover.

May be called any number of times, and each subscriber receives its own copy of the stream — subject to the buffering contract above. A subscriber that falls further behind than the configured capacity observes Lagged and skips the events it missed, rather than stalling the session’s event loop. Subscriptions taken here close if the prepared session is dropped without starting, or if startup fails.

Source

pub async fn start(self) -> Result<Session, Error>

Create or resume the session on the CLI.

This is where all protocol activity happens: config validation, router registration, the session.create / session.resume RPC, and the event loop spawn. Nothing observable occurs until this future is first polled.

§Errors

Returns the same errors as Client::create_session / Client::resume_session — including ErrorKind::InvalidConfig for invalid configs, transport and RPC failures, and SessionIdMismatch when the CLI returns a different session ID than the one requested. Every error path unregisters the session and closes subscriptions taken from this handle.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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