Struct dcl_rpc::messages_handlers::ClientMessagesHandler
source · pub struct ClientMessagesHandler {
pub transport: Arc<dyn Transport + Send + Sync>,
pub streams_handler: Arc<StreamsHandler>,
/* private fields */
}Expand description
ClientMessagesHandler is in charge of sending message through the transport, processing the responses and sending them through their attached listeners
It runs a background task listening for new messages (responses) in the given transport.
It’s the data structure that actually owns the Transport attached to a RpcClient. The transport is drilled down up to get to ClientMEssagesHandler
Fields§
§transport: Arc<dyn Transport + Send + Sync>Transport received by a RpcClient
streams_handler: Arc<StreamsHandler>Data structure in charge of handling all messages related to streams
Implementations§
source§impl ClientMessagesHandler
impl ClientMessagesHandler
pub fn new(transport: Arc<dyn Transport + Send + Sync>) -> Self
sourcepub fn start(self: Arc<Self>)
pub fn start(self: Arc<Self>)
Starts a background task to listen responses from the crate::server::RpcServer sent to the transport.
The receiver is an Arc<Self> in order to be able to process in a backgroun taks and mutate the state of the listeners
sourcepub fn await_server_ack_open_and_send_streams<M: Message + 'static>(
self: Arc<Self>,
open_promise: OneShotReceiver<Vec<u8>>,
client_stream: Generator<M>,
port_id: u32,
client_message_id: u32
)
pub fn await_server_ack_open_and_send_streams<M: Message + 'static>( self: Arc<Self>, open_promise: OneShotReceiver<Vec<u8>>, client_stream: Generator<M>, port_id: u32, client_message_id: u32 )
It spawns a background task to wait for the server to acknowledge the open of client streams or biderectional streams.
After the server acknowledges the open, it starts sending stram messages.
The receiver of the function is an Arc<Self> because an instance should be cloned for the background task and mutate the state of the message listeners
sourcepub async fn register_one_time_listener(
&self,
message_id: u32,
callback: OneShotSender<Vec<u8>>
)
pub async fn register_one_time_listener( &self, message_id: u32, callback: OneShotSender<Vec<u8>> )
Registers a one time listener. It will be used only one time and then removed.
sourcepub async fn register_listener(
&self,
message_id: u32,
callback: AsyncChannelSender<(RpcMessageTypes, u32, StreamMessage)>
)
pub async fn register_listener( &self, message_id: u32, callback: AsyncChannelSender<(RpcMessageTypes, u32, StreamMessage)> )
Registers a listener which will be more than one time
sourcepub async fn unregister_listener(&self, message_id: u32)
pub async fn unregister_listener(&self, message_id: u32)
Unregister a listener