Improve borrow handling
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -68,7 +68,7 @@ pub async fn run_data_live(
|
||||
_ => panic!(),
|
||||
}
|
||||
|
||||
let symbols = get_assets_with_class(&app_config.postgres_pool, class.clone())
|
||||
let symbols = get_assets_with_class(&app_config.postgres_pool, &class)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|asset| asset.symbol)
|
||||
@@ -88,17 +88,18 @@ pub async fn run_data_live(
|
||||
|
||||
spawn(broadcast_handler(
|
||||
class,
|
||||
asset_broadcast_receiver,
|
||||
sink.clone(),
|
||||
asset_broadcast_receiver,
|
||||
));
|
||||
|
||||
websocket_handler(app_config, sink, stream).await?;
|
||||
websocket_handler(app_config, class, sink, stream).await?;
|
||||
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
pub async fn websocket_handler(
|
||||
app_config: Arc<AppConfig>,
|
||||
class: Class,
|
||||
sink: Arc<RwLock<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>>>,
|
||||
stream: Arc<RwLock<SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>>>,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
@@ -111,12 +112,15 @@ pub async fn websocket_handler(
|
||||
for message in parsed_data {
|
||||
match message {
|
||||
IncomingMessage::Subscription(subscription_message) => {
|
||||
info!("Current subscriptions: {:?}", subscription_message.bars);
|
||||
info!(
|
||||
"Current {:?} subscriptions: {:?}",
|
||||
class, subscription_message.bars
|
||||
);
|
||||
}
|
||||
IncomingMessage::Bars(bar_message)
|
||||
| IncomingMessage::UpdatedBars(bar_message) => {
|
||||
debug!("Incoming bar: {:?}", bar_message);
|
||||
add_bar(&app_config.postgres_pool, Bar::from(bar_message)).await?;
|
||||
add_bar(&app_config.postgres_pool, &Bar::from(bar_message)).await?;
|
||||
}
|
||||
message => {
|
||||
warn!("Unhandled incoming message: {:?}", message);
|
||||
@@ -141,8 +145,8 @@ pub async fn websocket_handler(
|
||||
|
||||
pub async fn broadcast_handler(
|
||||
class: Class,
|
||||
mut asset_broadcast_receiver: Receiver<AssetBroadcastMessage>,
|
||||
sink: Arc<RwLock<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>>>,
|
||||
mut asset_broadcast_receiver: Receiver<AssetBroadcastMessage>,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
loop {
|
||||
match asset_broadcast_receiver.recv().await? {
|
||||
|
Reference in New Issue
Block a user