Struct barter_data::connection::ConnectionHandler [−][src]
pub struct ConnectionHandler<Message, Sub> {
pub rate_limit: Interval,
pub ws_conn: WSStream,
pub subscription_rx: Receiver<(Sub, UnboundedSender<Message>)>,
pub exchange_data_txs: HashMap<StreamRoutingId, UnboundedSender<Message>>,
}Expand description
Manages all connection related actions. This includes maintaining the WebSocket connection; re-connections; actioning Subscription requests received from an ExchangeClient; consuming incoming exchange messages from the WebSocket connection and routing them to the appropriate downstream consumer.
Fields
rate_limit: Intervalws_conn: WSStreamAn established WSStream connection that all ExchangeClient <–> ConnectionHandler communication goes through.
subscription_rx: Receiver<(Sub, UnboundedSender<Message>)>Subscription request channel receiver. Receives a tuple of Subscription and a data channel transmitter. This data channel transmitter is used to route messages relating to a particular Subscription back to the subscriber via the ExchangeClient implementation.
exchange_data_txs: HashMap<StreamRoutingId, UnboundedSender<Message>>Map containing the data channel transmitter for every Subscription actioned. The map’s StreamRoutingId key is used to identify which data channel to transmit an incoming exchange message to.
Implementations
impl<Message, Sub> ConnectionHandler<Message, Sub> where
Sub: Debug + Subscription + StreamIdentifier + Serialize + Send + Sync,
Message: Debug + StreamIdentifier + DeserializeOwned + Send + Sync,
impl<Message, Sub> ConnectionHandler<Message, Sub> where
Sub: Debug + Subscription + StreamIdentifier + Serialize + Send + Sync,
Message: Debug + StreamIdentifier + DeserializeOwned + Send + Sync,
Constructs a new ConnectionHandler instance using the WSStream connection provided.
Consumes two types of incoming messages Subscription requests received from an [ExchangeClient], and also the data received from an exchange as a result of a Subscription. This function handles the actioning of Subscription requests, and routes the exchange data to the associated downstream subscriber.
Subscribe asynchronously to a WebSocket data stream using the Subscription provided.