From e29c6849d0bd65a2aad21a8b78e0e39de01612bb Mon Sep 17 00:00:00 2001 From: Fedor Smirnov Date: Mon, 27 May 2024 19:38:05 +0200 Subject: [PATCH] Removed the nodelay example following review suggestion --- rumqttc/examples/asyncpubsub_nodelay.rs | 57 ------------------------- 1 file changed, 57 deletions(-) delete mode 100644 rumqttc/examples/asyncpubsub_nodelay.rs diff --git a/rumqttc/examples/asyncpubsub_nodelay.rs b/rumqttc/examples/asyncpubsub_nodelay.rs deleted file mode 100644 index 2671420af..000000000 --- a/rumqttc/examples/asyncpubsub_nodelay.rs +++ /dev/null @@ -1,57 +0,0 @@ -//! Same as asyncpubsub.rs but extended by configuring the client to not batch the messages -//! sent to the broker over TCP - -use tokio::{task, time}; - -use rumqttc::{AsyncClient, MqttOptions, QoS}; -use std::error::Error; -use std::time::Duration; - -#[tokio::main(flavor = "current_thread")] -async 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 eventloop) = AsyncClient::new(mqttoptions, 10); - // Configuring the client to not batch the messages sent to the broker over TCP - eventloop.network_options.set_tcp_nodelay(true); - - task::spawn(async move { - requests(client).await; - time::sleep(Duration::from_secs(3)).await; - }); - - loop { - let event = eventloop.poll().await; - match &event { - Ok(v) => { - println!("Event = {v:?}"); - } - Err(e) => { - println!("Error = {e:?}"); - return Ok(()); - } - } - } -} - -async fn requests(client: AsyncClient) { - client - .subscribe("hello/world", QoS::AtMostOnce) - .await - .unwrap(); - - for i in 1..=10 { - client - .publish("hello/world", QoS::ExactlyOnce, false, vec![1; i]) - .await - .unwrap(); - - time::sleep(Duration::from_secs(1)).await; - } - - time::sleep(Duration::from_secs(120)).await; -}