From 066783af548179c6c8d8cfc73db54d86776fe879 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Mon, 30 Sep 2024 23:13:19 +0530 Subject: [PATCH] rm unnecessary example --- rumqttc/examples/ack_promise_v5_sync.rs | 101 ------------------------ 1 file changed, 101 deletions(-) delete mode 100644 rumqttc/examples/ack_promise_v5_sync.rs diff --git a/rumqttc/examples/ack_promise_v5_sync.rs b/rumqttc/examples/ack_promise_v5_sync.rs deleted file mode 100644 index 26ae240dc..000000000 --- a/rumqttc/examples/ack_promise_v5_sync.rs +++ /dev/null @@ -1,101 +0,0 @@ -use flume::bounded; -use rumqttc::v5::{mqttbytes::QoS, Client, MqttOptions}; -use std::error::Error; -use std::thread; -use std::time::Duration; - -fn main() -> Result<(), Box> { - pretty_env_logger::init(); - // color_backtrace::install(); - - let mut mqttoptions = MqttOptions::new("test-1", "localhost", 1883); - mqttoptions.set_keep_alive(Duration::from_secs(5)); - - let (client, mut conn) = Client::new(mqttoptions, 10); - thread::spawn(move || { - for event in conn.iter() { - match &event { - Ok(v) => { - println!("Event = {v:?}"); - } - Err(e) => { - println!("Error = {e:?}"); - } - } - } - }); - - // Subscribe and wait for broker acknowledgement - let pkid = client - .subscribe("hello/world", QoS::AtMostOnce) - .unwrap() - .blocking_wait() - .unwrap(); - println!("Acknowledged Subscribe({pkid})"); - - // Publish at all QoS levels and wait for broker acknowledgement - let pkid = client - .publish("hello/world", QoS::AtMostOnce, false, vec![1; 1]) - .unwrap() - .blocking_wait() - .unwrap(); - println!("Acknowledged Pub({pkid})"); - - let pkid = client - .publish("hello/world", QoS::AtLeastOnce, false, vec![1; 2]) - .unwrap() - .blocking_wait() - .unwrap(); - println!("Acknowledged Pub({pkid})"); - - let pkid = client - .publish("hello/world", QoS::ExactlyOnce, false, vec![1; 3]) - .unwrap() - .blocking_wait() - .unwrap(); - println!("Acknowledged Pub({pkid})"); - - // Spawn threads for each publish, use channel to notify result - let (tx, rx) = bounded(1); - - let future = client - .publish("hello/world", QoS::AtMostOnce, false, vec![1; 1]) - .unwrap(); - let tx_clone = tx.clone(); - thread::spawn(move || { - let res = future.blocking_wait(); - tx_clone.send(res).unwrap() - }); - - let future = client - .publish("hello/world", QoS::AtLeastOnce, false, vec![1; 2]) - .unwrap(); - let tx_clone = tx.clone(); - thread::spawn(move || { - let res = future.blocking_wait(); - 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_wait(); - tx.send(res).unwrap() - }); - - while let Ok(res) = rx.recv() { - match res { - Ok(pkid) => println!("Acknowledged Pub({pkid})"), - Err(e) => println!("Publish failed: {e:?}"), - } - } - - // Unsubscribe and wait for broker acknowledgement - match client.unsubscribe("hello/world").unwrap().blocking_wait() { - Ok(pkid) => println!("Acknowledged Unsub({pkid})"), - Err(e) => println!("Unsubscription failed: {e:?}"), - } - - Ok(()) -}