Skip to content

Commit

Permalink
Explicitly ignore return value in Session::run() in samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
locka99 committed Apr 6, 2019
1 parent 679b153 commit 651ff8e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
24 changes: 19 additions & 5 deletions client/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<RwLock<Session>>) -> mpsc::Sender<()> {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
Expand All @@ -437,8 +449,9 @@ impl Session {
tx
}

/// Main running loop for a session
pub fn run_loop(session: Arc<RwLock<Session>>, 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<RwLock<Session>>, 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();
Expand Down Expand Up @@ -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<Mutex<dyn OnDataChange + Send + Sync + 'static>>)
-> Result<u32, StatusCode>
{
Expand Down
2 changes: 1 addition & 1 deletion samples/gfx-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ fn subscription_loop(nodes_to_monitor: Vec<ReadValueId>, session: Arc<RwLock<Ses
}

// Loops forever. The publish thread will call the callback with changes on the variables
Session::run(session);
let _ = Session::run(session);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion samples/mqtt-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn subscription_loop(session: Arc<RwLock<Session>>, 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(())
}
2 changes: 1 addition & 1 deletion samples/simple-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn subscription_loop(session: Arc<RwLock<Session>>) -> Result<(), StatusCode> {
}

// Loops forever. The publish thread will call the callback with changes on the variables
Session::run(session);
let _ = Session::run(session);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion samples/web-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn subscription_loop(session: Arc<RwLock<Session>>) -> Result<(), StatusCode> {
}

// Loops forever. The publish thread will call the callback with changes on the variables
Session::run(session);
let _ = Session::run(session);

Ok(())
}

0 comments on commit 651ff8e

Please sign in to comment.