pub struct SessionHandle { /* private fields */ }Expand description
Handle to a running SessionActor.
Cloning gives another caller the same mailbox and stream. When the last
handle drops, the session shuts down and its Agent is dropped.
Implementations§
Source§impl SessionHandle
impl SessionHandle
Sourcepub fn send(&self, request: Request) -> Result<(), SessionClosed>
pub fn send(&self, request: Request) -> Result<(), SessionClosed>
Submit a request to the session’s inbox.
Fails only if the session has shut down (every handle was dropped and the
actor task has ended). A Submit runs to completion before the next
non-interrupt request is serviced, but Interrupt/Wake/Cancel sent
during a run are handled immediately (see the actor’s delivery rules).
Sourcepub fn send_from(
&self,
from: SessionId,
request: Request,
) -> Result<(), SessionClosed>
pub fn send_from( &self, from: SessionId, request: Request, ) -> Result<(), SessionClosed>
Like SessionHandle::send, but attributed to a sender address so the
recipient can attribute and policy-check the message (a peer session
passes its own "agent:<id>" address).
Sourcepub async fn ask(&self, request: Request) -> Result<AgentEvent, SessionClosed>
pub async fn ask(&self, request: Request) -> Result<AgentEvent, SessionClosed>
Send a request and await its reply.
ask is for requests that expect a reply: GetHistory (→
AgentEvent::History), SetModel/SetEffort (→ AgentEvent::Ack
or AgentEvent::Error), Compact (→ AgentEvent::Compaction,
AgentEvent::Ack, or AgentEvent::Error). It also works for
Submit, replying when the run completes. Interrupts
(Interrupt/Wake/Cancel) want no reply — use send; an ask on one
still lands mid-run (the actor answers it Ack), so a server-side cancel
is never deferred.
Fails only if the session has shut down.
Sourcepub async fn ask_from(
&self,
from: SessionId,
request: Request,
) -> Result<AgentEvent, SessionClosed>
pub async fn ask_from( &self, from: SessionId, request: Request, ) -> Result<AgentEvent, SessionClosed>
Like SessionHandle::ask, attributed to a sender address.
Sourcepub fn state(&self) -> MemberState
pub fn state(&self) -> MemberState
The session’s current run-state. Read-only, lock-free (a watch borrow),
so a peers listing / roster read over N members is cheap.
Sourcepub fn state_rx(&self) -> Receiver<MemberState>
pub fn state_rx(&self) -> Receiver<MemberState>
A live view of the run-state, so a registry/server task can wake on a
transition instead of polling. Seeded with the current value (like
Registry::subscribe).
Sourcepub fn subscribe(&self) -> Receiver<AgentEvent>
pub fn subscribe(&self) -> Receiver<AgentEvent>
Subscribe to the session’s event stream. Each subscriber gets its own receiver; a lagging subscriber drops events rather than stalling the run.