pub struct ConnectionPool { /* private fields */ }Expand description
Manages multiple WebSocket connections keyed by SessionId.
Thread-safe, supports concurrent access from multiple Windows. All Firefox windows connect to the same port, messages routed by session.
§Example
ⓘ
let pool = ConnectionPool::new().await?;
println!("WebSocket URL: {}", pool.ws_url());
// Wait for a specific session to connect
let ready_data = pool.wait_for_session(session_id).await?;
// Send a request to that session
let response = pool.send(session_id, request).await?;Implementations§
Source§impl ConnectionPool
impl ConnectionPool
Source§impl ConnectionPool
impl ConnectionPool
Sourcepub fn ws_url(&self) -> String
pub fn ws_url(&self) -> String
Returns the WebSocket URL for this pool.
Format: ws://127.0.0.1:{port}
Sourcepub fn connection_count(&self) -> usize
pub fn connection_count(&self) -> usize
Returns the number of active connections.
Sourcepub async fn wait_for_session(&self, session_id: SessionId) -> Result<ReadyData>
pub async fn wait_for_session(&self, session_id: SessionId) -> Result<ReadyData>
Waits for a specific session to connect.
Called by spawn_window after launching Firefox.
Returns when Firefox with this sessionId connects and sends READY.
§Arguments
session_id- The session ID to wait for
§Errors
Error::ConnectionTimeoutif session doesn’t connect within 30s
Sourcepub async fn send(
&self,
session_id: SessionId,
request: Request,
) -> Result<Response>
pub async fn send( &self, session_id: SessionId, request: Request, ) -> Result<Response>
Sends a request to a specific session.
§Arguments
session_id- Target sessionrequest- Request to send
§Errors
Error::SessionNotFoundif session doesn’t existError::ConnectionClosedif connection is closedError::RequestTimeoutif response not received within timeout
Sourcepub async fn send_with_timeout(
&self,
session_id: SessionId,
request: Request,
request_timeout: Duration,
) -> Result<Response>
pub async fn send_with_timeout( &self, session_id: SessionId, request: Request, request_timeout: Duration, ) -> Result<Response>
Sends a request with custom timeout.
§Arguments
session_id- Target sessionrequest- Request to sendtimeout- Maximum time to wait for response
§Errors
Error::SessionNotFoundif session doesn’t existError::ConnectionClosedif connection is closedError::RequestTimeoutif response not received within timeout
Source§impl ConnectionPool
impl ConnectionPool
Sourcepub fn set_event_handler(&self, session_id: SessionId, handler: EventHandler)
pub fn set_event_handler(&self, session_id: SessionId, handler: EventHandler)
Sets the event handler for a session.
§Arguments
session_id- Target sessionhandler- Event handler callback
Sourcepub fn clear_event_handler(&self, session_id: SessionId)
pub fn clear_event_handler(&self, session_id: SessionId)
Auto Trait Implementations§
impl !Freeze for ConnectionPool
impl !RefUnwindSafe for ConnectionPool
impl Send for ConnectionPool
impl Sync for ConnectionPool
impl Unpin for ConnectionPool
impl !UnwindSafe for ConnectionPool
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
Mutably borrows from an owned value. Read more