pub struct SessionMap { /* private fields */ }Expand description
Maps Telegram chat IDs to daemon sessions.
Implementations§
Source§impl SessionMap
impl SessionMap
Sourcepub async fn get_session_id(&self, chat_id: ChatId) -> Option<SessionId>
pub async fn get_session_id(&self, chat_id: ChatId) -> Option<SessionId>
Get the session ID for a chat, if one exists.
Sourcepub async fn insert(&self, chat_id: ChatId, session_id: SessionId)
pub async fn insert(&self, chat_id: ChatId, session_id: SessionId)
Insert a new session mapping.
Also clears any in-progress creation lock for this chat to keep internal invariants consistent.
Sourcepub async fn try_start_existing_turn(&self, chat_id: ChatId) -> TurnStartResult
pub async fn try_start_existing_turn(&self, chat_id: ChatId) -> TurnStartResult
Atomically check if a session exists and start a turn.
Also returns TurnBusy if a session is currently being created for
this chat (prevents the caller from starting a duplicate creation).
Sourcepub async fn try_claim_creation(&self, chat_id: ChatId) -> bool
pub async fn try_claim_creation(&self, chat_id: ChatId) -> bool
Atomically claim the right to create a session for this chat.
Returns true if the caller should proceed with create_session.
Returns false if a session already exists or another task is
already creating one.
Sourcepub async fn finish_creation(&self, chat_id: ChatId, session_id: SessionId)
pub async fn finish_creation(&self, chat_id: ChatId, session_id: SessionId)
Complete session creation: insert the session and clear the creation lock.
Sourcepub async fn finish_creation_and_start_turn(
&self,
chat_id: ChatId,
session_id: SessionId,
) -> SessionId
pub async fn finish_creation_and_start_turn( &self, chat_id: ChatId, session_id: SessionId, ) -> SessionId
Atomically complete session creation and start a turn in one lock
acquisition. Prevents a race where another message starts the turn
between finish_creation and try_start_existing_turn.
Sourcepub async fn cancel_creation(&self, chat_id: ChatId)
pub async fn cancel_creation(&self, chat_id: ChatId)
Cancel session creation (on failure) and clear the creation lock.
Sourcepub async fn remove(&self, chat_id: ChatId) -> Option<SessionId>
pub async fn remove(&self, chat_id: ChatId) -> Option<SessionId>
Remove a session mapping.
Also clears any in-progress creation lock for this chat so a
concurrent finish_creation_and_start_turn doesn’t silently
re-insert the session after a /reset.
Sourcepub async fn try_start_turn(&self, chat_id: ChatId) -> bool
pub async fn try_start_turn(&self, chat_id: ChatId) -> bool
Atomically check and start a turn for this chat.
Returns true if the turn was started (was not already in progress).
Returns false if a turn is already in progress or no session exists.
Sourcepub async fn is_turn_in_progress(&self, chat_id: ChatId) -> bool
pub async fn is_turn_in_progress(&self, chat_id: ChatId) -> bool
Check if a turn is currently in progress for this chat.
Sourcepub async fn set_turn_in_progress(&self, chat_id: ChatId, in_progress: bool)
pub async fn set_turn_in_progress(&self, chat_id: ChatId, in_progress: bool)
Mark a turn as finished for this chat.
Trait Implementations§
Source§impl Clone for SessionMap
impl Clone for SessionMap
Source§fn clone(&self) -> SessionMap
fn clone(&self) -> SessionMap
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SessionMap
impl !RefUnwindSafe for SessionMap
impl Send for SessionMap
impl Sync for SessionMap
impl Unpin for SessionMap
impl UnsafeUnpin for SessionMap
impl !UnwindSafe for SessionMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Erasable for T
impl<T> Erasable for T
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more