pub struct BridgeDispatch { /* private fields */ }Expand description
Manages in-flight commands sent to the Chrome extension via native messaging.
Each command gets a UUID, is written to the native messaging stdout, and a oneshot receiver awaits the response from the extension.
Implementations§
Source§impl BridgeDispatch
impl BridgeDispatch
pub fn new<W: AsyncWrite + Send + Unpin + 'static>(writer: W) -> Self
Sourcepub fn new_sink() -> Self
pub fn new_sink() -> Self
Construct a dispatch whose frames are written to a discarding sink.
Use this in tests so dispatched native-messaging frames are not emitted
into cargo test stdout (which would corrupt the test output stream).
Sourcepub async fn dispatch(
&self,
tab_id: Option<u32>,
method: &str,
args: Value,
) -> Result<Value, String>
pub async fn dispatch( &self, tab_id: Option<u32>, method: &str, args: Value, ) -> Result<Value, String>
Send a command to the extension and await the response.
§Errors
Returns an error if the write fails, the extension disconnects, or the command times out (30s).
Sourcepub async fn on_response(
&self,
id: &str,
data: Option<Value>,
error: Option<String>,
)
pub async fn on_response( &self, id: &str, data: Option<Value>, error: Option<String>, )
Called by the native messaging read loop when a response arrives.
Sourcepub async fn cancel_all(&self)
pub async fn cancel_all(&self)
Drop all pending commands (e.g. on disconnect).
pub async fn pending_count(&self) -> usize
Sourcepub async fn pending_ids(&self) -> Vec<String>
pub async fn pending_ids(&self) -> Vec<String>
Return the IDs of all currently pending commands (for testing).
Sourcepub async fn register_test_pending(&self, id: &str) -> Receiver<DispatchResult>
pub async fn register_test_pending(&self, id: &str) -> Receiver<DispatchResult>
Insert a pending command directly and return the receiver (for testing).