Skip to content

Commit 9a62c18

Browse files
committed
fix(example): simplify event handling logic in TokioQuicMqttClient example
1 parent 7ab6f9d commit 9a62c18

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

examples/no_io_tokio_quic_client_example.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ async fn run_example() -> Result<(), Box<dyn std::error::Error>> {
4444
event = client.next_event() => {
4545
let Some(event) = event else { break; };
4646
match event {
47-
MqttEvent::Connected(_) => {
48-
if !subscribed {
49-
let sub_cmd = SubscribeCommand::builder().add_topic("test/topic/wrapper", 1).build()?;
50-
client.subscribe(sub_cmd).await.map_err(|e| e.to_string())?;
51-
subscribed = true;
52-
}
47+
MqttEvent::Connected(_)
48+
if !subscribed =>
49+
{
50+
let sub_cmd = SubscribeCommand::builder().add_topic("test/topic/wrapper", 1).build()?;
51+
client.subscribe(sub_cmd).await.map_err(|e| e.to_string())?;
52+
subscribed = true;
5353
}
54-
MqttEvent::Subscribed(res) => {
54+
MqttEvent::Subscribed(res)
55+
if !published =>
56+
{
5557
println!("Subscribed: ID={:?}", res.packet_id);
56-
if !published {
57-
let pub_cmd = PublishCommand::builder().topic("test/topic/wrapper").payload("Hello!".to_string()).qos(1).build()?;
58-
client.publish(pub_cmd).await.map_err(|e| e.to_string())?;
59-
published = true;
60-
}
58+
let pub_cmd = PublishCommand::builder().topic("test/topic/wrapper").payload("Hello!".to_string()).qos(1).build()?;
59+
client.publish(pub_cmd).await.map_err(|e| e.to_string())?;
60+
published = true;
6161
}
6262
MqttEvent::Published(res) => {
6363
println!("Published: ID={:?}", res.packet_id);

0 commit comments

Comments
 (0)