too many 'shutdown' can be ambiguous

This commit is contained in:
Ting Sun
2023-03-20 03:38:46 +08:00
committed by Carl Lerche
parent c1c3bcb465
commit 017a0df61f

View File

@@ -12,7 +12,7 @@ use tokio::sync::broadcast;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct Shutdown { pub(crate) struct Shutdown {
/// `true` if the shutdown signal has been received /// `true` if the shutdown signal has been received
shutdown: bool, is_shutdown: bool,
/// The receive half of the channel used to listen for shutdown. /// The receive half of the channel used to listen for shutdown.
notify: broadcast::Receiver<()>, notify: broadcast::Receiver<()>,
@@ -22,21 +22,21 @@ impl Shutdown {
/// Create a new `Shutdown` backed by the given `broadcast::Receiver`. /// Create a new `Shutdown` backed by the given `broadcast::Receiver`.
pub(crate) fn new(notify: broadcast::Receiver<()>) -> Shutdown { pub(crate) fn new(notify: broadcast::Receiver<()>) -> Shutdown {
Shutdown { Shutdown {
shutdown: false, is_shutdown: false,
notify, notify,
} }
} }
/// Returns `true` if the shutdown signal has been received. /// Returns `true` if the shutdown signal has been received.
pub(crate) fn is_shutdown(&self) -> bool { pub(crate) fn is_shutdown(&self) -> bool {
self.shutdown self.is_shutdown
} }
/// Receive the shutdown notice, waiting if necessary. /// Receive the shutdown notice, waiting if necessary.
pub(crate) async fn recv(&mut self) { pub(crate) async fn recv(&mut self) {
// If the shutdown signal has already been received, then return // If the shutdown signal has already been received, then return
// immediately. // immediately.
if self.shutdown { if self.is_shutdown {
return; return;
} }
@@ -44,6 +44,6 @@ impl Shutdown {
let _ = self.notify.recv().await; let _ = self.notify.recv().await;
// Remember that the signal has been received. // Remember that the signal has been received.
self.shutdown = true; self.is_shutdown = true;
} }
} }