Skip to main content

SessionHandle

Struct SessionHandle 

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

A cloneable operation entry for one Session.

Handles never own the lifecycle: dropping the last handle does not close the session, and after the owner is dropped they can still read retained observations and replay an accepted request_key to its original receipt, while new submissions are refused with SessionError::Closed.

Implementations§

Source§

impl SessionHandle

Source

pub fn id(&self) -> ConversationId

The conversation this handle operates on.

Source

pub fn submit( &self, request: SubmitRequest, ) -> Result<WorkReceipt, SessionError>

Submit one new work.

Accepts on an idle session, atomically allocates a fresh turn id, writes the request parts as the turn’s first fact block, and spawns the worker. Rejections (busy, conflict, capacity, invalid input, closed, faulted) leave no accepted work behind and do not consume the request key. Idempotent on request_key + parts: a repeat returns the original receipt without executing again, even once the owner has closed.

Synchronous: admission never blocks on the runner. Spawning the worker still requires a Tokio runtime context.

§Errors

See SessionError.

Source

pub fn observe(&self, work: &WorkRef) -> Result<WorkObservation, SessionError>

Read one work’s current published state.

A paused observation includes the prepared calls needed to construct a resume decision, copied from the same revision. Never blocks on the runner and never mutates the work.

§Errors

SessionError::NotFound if the ref does not belong to this session.

Source

pub async fn wait( &self, work: &WorkRef, timeout: Duration, ) -> Result<WaitOutcome, SessionError>

Wait finitely for a work to reach Paused / Finished / Faulted.

Returns as soon as one of those states is observed, or TimedOut with a consistent snapshot when timeout elapses first; a wakeup is never lost, and timing out does not change the work’s state.

§Errors

SessionError::NotFound if the ref does not belong to this session.

Source

pub fn resume( &self, work: &WorkRef, expected_revision: u64, request_key: String, request: ResumeRequest, ) -> Result<WorkReceipt, SessionError>

Continue a paused work.

Validates the ref, the work’s current paused revision, and the request against the paused continuation before anything runs: a rejected request executes nothing and leaves the paused material untouched. On acceptance the work returns to Running in the same turn id and continues under the deadline measured from its original acceptance. Idempotent on request_key + (work, expected_revision, request): a same-key repeat returns the original receipt without re-executing, while the same key with a different decision or injection is SessionError::Conflict.

Synchronous: admission never blocks on the runner.

§Errors

SessionError::NotFound for a foreign or unknown ref, SessionError::NotPaused when the work is not paused, SessionError::StaleRevision when expected_revision is not the work’s current paused revision, SessionError::Busy while another work owns the conversation, SessionError::InvalidResume when the driver rejects the request, SessionError::Conflict on a key reuse with different arguments, and SessionError::Closed for a request that is not a replay after shutdown.

Source

pub fn resume_receipt( &self, work: &WorkRef, expected_revision: u64, request_key: &str, request: &ResumeRequest, ) -> Result<Option<WorkReceipt>, SessionError>

Read the receipt of an already-accepted resume without starting work.

Hosts can resolve a retry before applying their own capacity gate. Some is the original receipt for exactly these arguments; None means this session has not accepted the key. Neither outcome changes the work, consumes the key, nor requires a paused or open session. A missing record does not reserve admission: a later Self::resume still performs its atomic replay and state checks.

§Errors

SessionError::Conflict if this key was accepted with a different work, paused revision, or request.

Source

pub fn cancel( &self, work: &WorkRef, request_key: String, ) -> Result<CancelReceipt, SessionError>

Cancel one work.

Fires the work’s own control token while it runs — a completion that races the cancel keeps its result — or terminates a paused work in place, retaining its committed facts and continuation. A work that already finished is never rewritten. Idempotent on request_key: a same-key retry returns the original receipt.

Synchronous: admission never blocks on the runner.

§Errors

SessionError::NotFound for a foreign, unknown, or already-cleared ref, SessionError::Busy while another work owns the conversation, SessionError::Conflict on a key reuse with a different work, and SessionError::Closed for a request that is not a replay after shutdown.

Trait Implementations§

Source§

impl Clone for SessionHandle

Source§

fn clone(&self) -> SessionHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SessionHandle

Source§

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

Formats the value using the given formatter. Read more

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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