pub struct Connection { /* private fields */ }Expand description
WebSocket connection to Firefox extension.
Handles request/response correlation and event routing. The connection spawns an internal event loop task.
§Thread Safety
Connection is Send + Sync and can be shared across tasks.
All operations are non-blocking.
Implementations§
Source§impl Connection
impl Connection
Sourcepub async fn wait_ready(&self) -> Result<ReadyData>
pub async fn wait_ready(&self) -> Result<ReadyData>
Waits for the READY handshake message.
Must be called after connection is established. The extension sends READY with nil UUID immediately after connecting.
§Errors
Error::ConnectionTimeoutif READY not received within 30sError::ConnectionClosedif connection closes before READY
Sourcepub fn add_event_handler(&self, key: String, handler: EventHandler)
pub fn add_event_handler(&self, key: String, handler: EventHandler)
Adds an event handler with a key label.
Multiple handlers can be registered simultaneously.
When an event arrives, handlers are iterated in order until
one returns Some(EventReply).
If a handler with the same key already exists, it is replaced.
Sourcepub fn remove_event_handler(&self, key: &str)
pub fn remove_event_handler(&self, key: &str)
Removes an event handler by key.
Sourcepub fn clear_all_event_handlers(&self)
pub fn clear_all_event_handlers(&self)
Clears all event handlers (for shutdown).
Sourcepub async fn send(&self, request: Request) -> Result<Response>
pub async fn send(&self, request: Request) -> Result<Response>
Sends a request and waits for response with default timeout (30s).
§Errors
Error::ConnectionClosedif connection is closedError::RequestTimeoutif response not received within timeoutError::Protocolif too many pending requests
Sourcepub async fn send_with_timeout(
&self,
request: Request,
request_timeout: Duration,
) -> Result<Response>
pub async fn send_with_timeout( &self, request: Request, request_timeout: Duration, ) -> Result<Response>
Sends a request and waits for response with custom timeout.
§Arguments
request- The request to sendrequest_timeout- Maximum time to wait for response
§Errors
Error::ConnectionClosedif connection is closedError::RequestTimeoutif response not received within timeoutError::Protocolif too many pending requests
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Returns the number of pending requests.