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 set_event_handler(&self, handler: EventHandler)
pub fn set_event_handler(&self, handler: EventHandler)
Sets the event handler callback.
The handler is called for each event received from the extension.
Return Some(EventReply) to send a reply back.
Sourcepub fn clear_event_handler(&self)
pub fn clear_event_handler(&self)
Clears the event handler.
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.
Trait Implementations§
Source§impl Clone for Connection
impl Clone for Connection
Auto Trait Implementations§
impl Freeze for Connection
impl !RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl !UnwindSafe for Connection
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