//! Cancellation of an in-flight resolver request. use commonware_actor::mailbox::{Policy, Sender}; /// Sends its message on drop, unless [`Guard::disarm`] ran first. pub(super) struct Guard { sender: Sender, cancel: Option, } impl Guard { pub(super) const fn new(sender: Sender, cancel: T) -> Self { Self { sender, cancel: Some(cancel), } } /// Suppresses the drop-time cancel; call once the fetch has completed. pub(super) fn disarm(&mut self) { self.cancel = None; } } impl Drop for Guard { fn drop(&mut self) { let Some(cancel) = self.cancel.take() else { return; }; let _ = self.sender.enqueue(cancel); } }