Expand description
Global pending response registry for bidirectional communication
This module provides a global registry for pending bidirectional requests, enabling transports like MCP (which are fundamentally request-response) to route responses back to the correct BidirChannel.
§Architecture
- When a BidirChannel sends a request, it registers a callback in this registry
- The transport (e.g., MCP) sends the request to the client as a notification
- The client responds via a tool call (e.g.,
_plexus_respond) - The transport looks up the request in this registry and forwards the response
- The registry callback deserializes and sends to the waiting BidirChannel
§Thread Safety
The registry uses a RwLock for concurrent read access with exclusive write access. Registrations and lookups are fast; response handling is done outside the lock.
Functions§
- handle_
pending_ response - Handle a response for a pending request
- is_
request_ pending - Check if a request is pending
- pending_
count - Get the count of pending requests (for monitoring/debugging)
- register_
pending_ request - Register a pending request in the global registry
- unregister_
pending_ request - Remove a pending request from the registry (e.g., on timeout)