Skip to content

Commit aa4fecb

Browse files
committed
style: Use while let pattern in reconnect example
1 parent 1b9acd5 commit aa4fecb

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

examples/reconnect.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4848
info!("Subscribed to {} on {}", symbol, exchange);
4949
}
5050

51-
// Inner loop: process until disconnect
52-
loop {
53-
match handle.subscription_receiver.recv().await {
54-
Ok(update) => match &update.message {
55-
RithmicMessage::HeartbeatTimeout
56-
| RithmicMessage::ForcedLogout(_)
57-
| RithmicMessage::ConnectionError => {
58-
warn!("Disconnected, reconnecting...");
59-
break;
60-
}
61-
RithmicMessage::LastTrade(t) => {
62-
info!(
63-
"Trade: {} @ {}",
64-
t.trade_size.unwrap_or(0),
65-
t.trade_price.unwrap_or(0.0)
66-
);
67-
}
68-
_ => {}
69-
},
70-
Err(_) => break,
51+
// Process until disconnect
52+
while let Ok(update) = handle.subscription_receiver.recv().await {
53+
match &update.message {
54+
RithmicMessage::HeartbeatTimeout
55+
| RithmicMessage::ForcedLogout(_)
56+
| RithmicMessage::ConnectionError => {
57+
warn!("Disconnected, reconnecting...");
58+
break;
59+
}
60+
RithmicMessage::LastTrade(t) => {
61+
info!(
62+
"Trade: {} @ {}",
63+
t.trade_size.unwrap_or(0),
64+
t.trade_price.unwrap_or(0.0)
65+
);
66+
}
67+
_ => {}
7168
}
7269
}
7370

0 commit comments

Comments
 (0)