Skip to content

Commit

Permalink
watch::Sender Improve readability of send_if_modified()
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Apr 3, 2022
1 parent 2acc5de commit 0c360a4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tokio/src/sync/watch.rs
Expand Up @@ -641,18 +641,19 @@ impl<T> Sender<T> {
// Update the value and catch possible panic inside func.
let result = panic::catch_unwind(panic::AssertUnwindSafe(|| modify(&mut lock)));
match result {
Ok(true) => {
Ok(modified) => {
if !modified {
// Abort, i.e. don't notify receivers if unmodified
return false;
}
// Continue if modified
},
Ok(false) => {
// Don't notify receivers if unmodified
return false;
}
Err(panicked) => {
// Drop the lock to avoid poisoning it.
drop(lock);
// Forward the panic to the caller.
panic::resume_unwind(panicked);
// Unreachable
}
};

Expand Down

0 comments on commit 0c360a4

Please sign in to comment.