Skip to content

Commit

Permalink
doc: update example with pkids
Browse files Browse the repository at this point in the history
  • Loading branch information
Devdutt Shenoi committed Sep 30, 2024
1 parent 8ad2223 commit db7c322
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 52 deletions.
26 changes: 13 additions & 13 deletions rumqttc/examples/ack_promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,38 @@ async fn main() -> Result<(), Box<dyn Error>> {
});

// Subscribe and wait for broker acknowledgement
client
let pkid = client
.subscribe("hello/world", QoS::AtMostOnce)
.await
.unwrap()
.await
.unwrap();
println!("Acknowledged Subscribe");
println!("Acknowledged Subscribe({pkid})");

// Publish at all QoS levels and wait for broker acknowledgement
client
let pkid = client
.publish("hello/world", QoS::AtMostOnce, false, vec![1; 1])
.await
.unwrap()
.await
.unwrap();
println!("Acknowledged Pub(1)");
println!("Acknowledged Pub({pkid})");

client
let pkid = client
.publish("hello/world", QoS::AtLeastOnce, false, vec![1; 2])
.await
.unwrap()
.await
.unwrap();
println!("Acknowledged Pub(2)");
println!("Acknowledged Pub({pkid})");

client
let pkid = client
.publish("hello/world", QoS::ExactlyOnce, false, vec![1; 3])
.await
.unwrap()
.await
.unwrap();
println!("Acknowledged Pub(3)");
println!("Acknowledged Pub({pkid})");

// Publish and spawn wait for notification
let mut set = JoinSet::new();
Expand All @@ -68,22 +68,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
.publish("hello/world", QoS::AtMostOnce, false, vec![1; 1])
.await
.unwrap();
set.spawn(async { future.await.map(|_| 1) });
set.spawn(async { future.await });

let future = client
.publish("hello/world", QoS::AtLeastOnce, false, vec![1; 2])
.await
.unwrap();
set.spawn(async { future.await.map(|_| 2) });
set.spawn(async { future.await });

let future = client
.publish("hello/world", QoS::ExactlyOnce, false, vec![1; 3])
.await
.unwrap();
set.spawn(async { future.await.map(|_| 3) });
set.spawn(async { future.await });

while let Some(res) = set.join_next().await {
println!("Acknowledged = {:?}", res?);
while let Some(Ok(Ok(pkid))) = set.join_next().await {
println!("Acknowledged Pub({pkid})");
}

Ok(())
Expand Down
26 changes: 13 additions & 13 deletions rumqttc/examples/ack_promise_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@ fn main() -> Result<(), Box<dyn Error>> {
});

// Subscribe and wait for broker acknowledgement
client
let pkid = client
.subscribe("hello/world", QoS::AtMostOnce)
.unwrap()
.blocking_recv()
.unwrap();
println!("Acknowledged Subscribe");
println!("Acknowledged Subscribe({pkid})");

// Publish at all QoS levels and wait for broker acknowledgement
client
let pkid = client
.publish("hello/world", QoS::AtMostOnce, false, vec![1; 1])
.unwrap()
.blocking_recv()
.unwrap();
println!("Acknowledged Pub(1)");
println!("Acknowledged Pub({pkid})");

client
let pkid = client
.publish("hello/world", QoS::AtLeastOnce, false, vec![1; 2])
.unwrap()
.blocking_recv()
.unwrap();
println!("Acknowledged Pub(2)");
println!("Acknowledged Pub({pkid})");

client
let pkid = client
.publish("hello/world", QoS::ExactlyOnce, false, vec![1; 3])
.unwrap()
.blocking_recv()
.unwrap();
println!("Acknowledged Pub(3)");
println!("Acknowledged Pub({pkid})");

// Spawn threads for each publish, use channel to notify result
let (tx, rx) = bounded(1);
Expand All @@ -63,7 +63,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.unwrap();
let tx_clone = tx.clone();
thread::spawn(move || {
let res = future.blocking_recv().map(|_| 1);
let res = future.blocking_recv();
tx_clone.send(res).unwrap()
});

Expand All @@ -72,20 +72,20 @@ fn main() -> Result<(), Box<dyn Error>> {
.unwrap();
let tx_clone = tx.clone();
thread::spawn(move || {
let res = future.blocking_recv().map(|_| 2);
let res = future.blocking_recv();
tx_clone.send(res).unwrap()
});

let future = client
.publish("hello/world", QoS::ExactlyOnce, false, vec![1; 3])
.unwrap();
thread::spawn(move || {
let res = future.blocking_recv().map(|_| 3);
let res = future.blocking_recv();
tx.send(res).unwrap()
});

while let Ok(res) = rx.recv() {
println!("Acknowledged = {:?}", res?);
while let Ok(Ok(pkid)) = rx.recv() {
println!("Acknowledged Pub({:?})", pkid);
}

Ok(())
Expand Down
26 changes: 13 additions & 13 deletions rumqttc/examples/ack_promise_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,38 @@ async fn main() -> Result<(), Box<dyn Error>> {
});

// Subscribe and wait for broker acknowledgement
client
let pkid = client
.subscribe("hello/world", QoS::AtMostOnce)
.await
.unwrap()
.await
.unwrap();
println!("Acknowledged Subscribe");
println!("Acknowledged Subscribe({pkid})");

// Publish at all QoS levels and wait for broker acknowledgement
client
let pkid = client
.publish("hello/world", QoS::AtMostOnce, false, vec![1; 1])
.await
.unwrap()
.await
.unwrap();
println!("Acknowledged Pub(1)");
println!("Acknowledged Pub({pkid})");

client
let pkid = client
.publish("hello/world", QoS::AtLeastOnce, false, vec![1; 2])
.await
.unwrap()
.await
.unwrap();
println!("Acknowledged Pub(2)");
println!("Acknowledged Pub({pkid})");

client
let pkid = client
.publish("hello/world", QoS::ExactlyOnce, false, vec![1; 3])
.await
.unwrap()
.await
.unwrap();
println!("Acknowledged Pub(3)");
println!("Acknowledged Pub({pkid})");

// Publish and spawn wait for notification
let mut set = JoinSet::new();
Expand All @@ -68,22 +68,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
.publish("hello/world", QoS::AtMostOnce, false, vec![1; 1])
.await
.unwrap();
set.spawn(async { future.await.map(|_| 1) });
set.spawn(async { future.await });

let future = client
.publish("hello/world", QoS::AtLeastOnce, false, vec![1; 2])
.await
.unwrap();
set.spawn(async { future.await.map(|_| 2) });
set.spawn(async { future.await });

let future = client
.publish("hello/world", QoS::ExactlyOnce, false, vec![1; 3])
.await
.unwrap();
set.spawn(async { future.await.map(|_| 3) });
set.spawn(async { future.await });

while let Some(res) = set.join_next().await {
println!("Acknowledged = {:?}", res?);
while let Some(Ok(Ok(pkid))) = set.join_next().await {
println!("Acknowledged Pub({pkid})");
}

Ok(())
Expand Down
26 changes: 13 additions & 13 deletions rumqttc/examples/ack_promise_v5_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@ fn main() -> Result<(), Box<dyn Error>> {
});

// Subscribe and wait for broker acknowledgement
client
let pkid = client
.subscribe("hello/world", QoS::AtMostOnce)
.unwrap()
.blocking_recv()
.unwrap();
println!("Acknowledged Subscribe");
println!("Acknowledged Subscribe({pkid})");

// Publish at all QoS levels and wait for broker acknowledgement
client
let pkid = client
.publish("hello/world", QoS::AtMostOnce, false, vec![1; 1])
.unwrap()
.blocking_recv()
.unwrap();
println!("Acknowledged Pub(1)");
println!("Acknowledged Pub({pkid})");

client
let pkid = client
.publish("hello/world", QoS::AtLeastOnce, false, vec![1; 2])
.unwrap()
.blocking_recv()
.unwrap();
println!("Acknowledged Pub(2)");
println!("Acknowledged Pub({pkid})");

client
let pkid = client
.publish("hello/world", QoS::ExactlyOnce, false, vec![1; 3])
.unwrap()
.blocking_recv()
.unwrap();
println!("Acknowledged Pub(3)");
println!("Acknowledged Pub({pkid})");

// Spawn threads for each publish, use channel to notify result
let (tx, rx) = bounded(1);
Expand All @@ -63,7 +63,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.unwrap();
let tx_clone = tx.clone();
thread::spawn(move || {
let res = future.blocking_recv().map(|_| 1);
let res = future.blocking_recv();
tx_clone.send(res).unwrap()
});

Expand All @@ -72,20 +72,20 @@ fn main() -> Result<(), Box<dyn Error>> {
.unwrap();
let tx_clone = tx.clone();
thread::spawn(move || {
let res = future.blocking_recv().map(|_| 2);
let res = future.blocking_recv();
tx_clone.send(res).unwrap()
});

let future = client
.publish("hello/world", QoS::ExactlyOnce, false, vec![1; 3])
.unwrap();
thread::spawn(move || {
let res = future.blocking_recv().map(|_| 3);
let res = future.blocking_recv();
tx.send(res).unwrap()
});

while let Ok(res) = rx.recv() {
println!("Acknowledged = {:?}", res?);
while let Ok(Ok(pkid)) = rx.recv() {
println!("Acknowledged Pub({:?})", pkid);
}

Ok(())
Expand Down

0 comments on commit db7c322

Please sign in to comment.