pub struct MultiSessionManager<T: AsyncReadExt + AsyncWriteExt + Unpin + Send + 'static> { /* private fields */ }Expand description
Manager for multiple async sessions with select capabilities.
This provides the core multi-session functionality, allowing you to:
- Manage multiple sessions simultaneously
- Wait for any session to match a pattern (
expect_any) - Wait for all sessions to match patterns (
expect_all) - Send to multiple sessions in parallel
- Select on multiple sessions with different patterns per session
Implementations§
Source§impl<T: AsyncReadExt + AsyncWriteExt + Unpin + Send + 'static> MultiSessionManager<T>
impl<T: AsyncReadExt + AsyncWriteExt + Unpin + Send + 'static> MultiSessionManager<T>
Sourcepub const fn with_timeout(self, timeout: Duration) -> Self
pub const fn with_timeout(self, timeout: Duration) -> Self
Set the default timeout for operations.
Sourcepub fn with_config(self, config: SessionConfig) -> Self
pub fn with_config(self, config: SessionConfig) -> Self
Set the default session configuration.
Sourcepub fn add(
&mut self,
session: Session<T>,
label: impl Into<String>,
) -> SessionId
pub fn add( &mut self, session: Session<T>, label: impl Into<String>, ) -> SessionId
Add an existing session to the manager.
Returns the assigned session ID.
Sourcepub async fn remove(&mut self, id: SessionId) -> Option<Session<T>>
pub async fn remove(&mut self, id: SessionId) -> Option<Session<T>>
Remove a session from the manager.
Returns the session if it existed.
Sourcepub fn session_ids(&self) -> Vec<SessionId> ⓘ
pub fn session_ids(&self) -> Vec<SessionId> ⓘ
Get all session IDs.
Sourcepub async fn set_active(&self, id: SessionId, active: bool)
pub async fn set_active(&self, id: SessionId, active: bool)
Set a session’s active state.
Sourcepub async fn active_ids(&self) -> Vec<SessionId> ⓘ
pub async fn active_ids(&self) -> Vec<SessionId> ⓘ
Get active session IDs.
Sourcepub async fn send(&self, id: SessionId, data: &[u8]) -> Result<()>
pub async fn send(&self, id: SessionId, data: &[u8]) -> Result<()>
Send data to a specific session.
§Errors
Returns an error if the session doesn’t exist or the send fails.
Sourcepub async fn send_line(&self, id: SessionId, line: &str) -> Result<()>
pub async fn send_line(&self, id: SessionId, line: &str) -> Result<()>
Send a line to a specific session.
§Errors
Returns an error if the session doesn’t exist or the send fails.
Sourcepub async fn send_all(&self, data: &[u8]) -> Vec<SendResult>
pub async fn send_all(&self, data: &[u8]) -> Vec<SendResult>
Send data to all active sessions in parallel.
Returns results for each session.
Sourcepub async fn expect(
&self,
id: SessionId,
pattern: impl Into<Pattern>,
) -> Result<Match>
pub async fn expect( &self, id: SessionId, pattern: impl Into<Pattern>, ) -> Result<Match>
Expect a pattern on a specific session.
§Errors
Returns an error if the session doesn’t exist or expect fails.
Sourcepub async fn expect_any(
&self,
pattern: impl Into<Pattern>,
) -> Result<SelectResult>
pub async fn expect_any( &self, pattern: impl Into<Pattern>, ) -> Result<SelectResult>
Wait for any session to match the given pattern.
Returns as soon as any session matches. This is the primary multi-session select operation, equivalent to TCL Expect’s multi-spawn expect.
§Errors
Returns an error if all sessions timeout or encounter errors.
Sourcepub async fn expect_any_of(&self, patterns: &[Pattern]) -> Result<SelectResult>
pub async fn expect_any_of(&self, patterns: &[Pattern]) -> Result<SelectResult>
Wait for any session to match any of the given patterns.
§Errors
Returns an error if all sessions timeout or encounter errors.
Sourcepub async fn expect_all(
&self,
pattern: impl Into<Pattern>,
) -> Result<Vec<SelectResult>>
pub async fn expect_all( &self, pattern: impl Into<Pattern>, ) -> Result<Vec<SelectResult>>
Wait for all sessions to match patterns.
Each session must match at least one pattern. Returns results for all sessions.
§Errors
Returns an error if any session fails to match.
Sourcepub async fn expect_all_of(
&self,
patterns: &[Pattern],
) -> Result<Vec<SelectResult>>
pub async fn expect_all_of( &self, patterns: &[Pattern], ) -> Result<Vec<SelectResult>>
Wait for all sessions to match any of the given patterns.
§Errors
Returns an error if any session fails.
Sourcepub async fn with_session<F, R>(&self, id: SessionId, f: F) -> Result<R>
pub async fn with_session<F, R>(&self, id: SessionId, f: F) -> Result<R>
Execute a closure on a specific session.
This provides direct access to the session for operations not covered by the manager’s API.
§Errors
Returns an error if the session doesn’t exist.