From 0c360a4f6f92d9bcd19924026dd4c044f7bbf9d2 Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Sun, 3 Apr 2022 14:18:21 +0200 Subject: [PATCH] watch::Sender Improve readability of send_if_modified() --- tokio/src/sync/watch.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tokio/src/sync/watch.rs b/tokio/src/sync/watch.rs index 401b68b50e4..273c96c8032 100644 --- a/tokio/src/sync/watch.rs +++ b/tokio/src/sync/watch.rs @@ -641,18 +641,19 @@ impl Sender { // 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 } };