From 651ff8e7fde29b169eea5a5248fc33f1e33694fe Mon Sep 17 00:00:00 2001 From: Adam Lock Date: Sat, 6 Apr 2019 20:59:29 +0100 Subject: [PATCH] Explicitly ignore return value in Session::run() in samples. --- client/src/session.rs | 24 +++++++++++++++++++----- samples/gfx-client/src/main.rs | 2 +- samples/mqtt-client/src/main.rs | 2 +- samples/simple-client/src/main.rs | 2 +- samples/web-client/src/main.rs | 2 +- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/client/src/session.rs b/client/src/session.rs index f979c7ad2..d45313efb 100644 --- a/client/src/session.rs +++ b/client/src/session.rs @@ -416,6 +416,9 @@ impl Session { /// as well as recovering from connection errors. The run command will break if the session is disconnected /// and cannot be reestablished. /// + /// The `run()` function returns a `Sender` that can be used to send a `()` message to the session + /// to cause it to terminate. + /// /// # Returns /// /// * `mpsc::Sender<()>` - A sender that allows the caller to send a single unity message to the @@ -427,8 +430,17 @@ impl Session { tx } - /// Runs the server asynchronously by spawning a thread for it to run on, allowing the calling - /// thread to proceed to do other things. + /// Runs the server asynchronously on a new thread, allowing the calling + /// thread to continue do other things. + /// + /// The `run()` function returns a `Sender` that can be used to send a `()` message to the session + /// to cause it to terminate. + /// + /// # Returns + /// + /// * `mpsc::Sender<()>` - A sender that allows the caller to send a single unity message to the + /// run loop to cause it to abort. + /// pub fn run_async(session: Arc>) -> mpsc::Sender<()> { let (tx, rx) = mpsc::channel(); thread::spawn(move || { @@ -437,8 +449,9 @@ impl Session { tx } - /// Main running loop for a session - pub fn run_loop(session: Arc>, sleep_interval: u64, rx: mpsc::Receiver<()>) { + /// The main running loop for a session. This is used by `run()` and `run_async()` to run + /// continuously until a signal is received to terminate. + fn run_loop(session: Arc>, sleep_interval: u64, rx: mpsc::Receiver<()>) { loop { // Main thread has nothing to do - just wait for publish events to roll in let mut session = session.write().unwrap(); @@ -1198,7 +1211,8 @@ impl Session { } /// This is the internal handler for create subscription that receives the callback wrapped up and reference counted. - fn create_subscription_inner(&mut self, publishing_interval: f64, lifetime_count: u32, max_keep_alive_count: u32, max_notifications_per_publish: u32, priority: u8, publishing_enabled: bool, + fn create_subscription_inner(&mut self, publishing_interval: f64, lifetime_count: u32, max_keep_alive_count: u32, max_notifications_per_publish: u32, + priority: u8, publishing_enabled: bool, callback: Arc>) -> Result { diff --git a/samples/gfx-client/src/main.rs b/samples/gfx-client/src/main.rs index 674704551..3d95bdf10 100644 --- a/samples/gfx-client/src/main.rs +++ b/samples/gfx-client/src/main.rs @@ -169,7 +169,7 @@ fn subscription_loop(nodes_to_monitor: Vec, session: Arc>, tx: mpsc::Sender<(NodeId, Da } // Loops forever. The publish thread will call the callback with changes on the variables - Session::run(session); + let _ = Session::run(session); Ok(()) } diff --git a/samples/simple-client/src/main.rs b/samples/simple-client/src/main.rs index 322ad9a14..c43d786ad 100644 --- a/samples/simple-client/src/main.rs +++ b/samples/simple-client/src/main.rs @@ -72,7 +72,7 @@ fn subscription_loop(session: Arc>) -> Result<(), StatusCode> { } // Loops forever. The publish thread will call the callback with changes on the variables - Session::run(session); + let _ = Session::run(session); Ok(()) } diff --git a/samples/web-client/src/main.rs b/samples/web-client/src/main.rs index 53559f162..e44c6969b 100644 --- a/samples/web-client/src/main.rs +++ b/samples/web-client/src/main.rs @@ -156,7 +156,7 @@ fn subscription_loop(session: Arc>) -> Result<(), StatusCode> { } // Loops forever. The publish thread will call the callback with changes on the variables - Session::run(session); + let _ = Session::run(session); Ok(()) } \ No newline at end of file