From d757d87365ced0e3f086c7f92b759d500c02381e Mon Sep 17 00:00:00 2001 From: ZhennanWu <38578020+ZhennanWu@users.noreply.github.com> Date: Sat, 18 Feb 2023 18:22:28 -0800 Subject: [PATCH] add AbortHandle::is_aborted() (#2710) Co-authored-by: ZhennanWu --- futures-util/src/abortable.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/futures-util/src/abortable.rs b/futures-util/src/abortable.rs index e0afd47218..cb81ce32cd 100644 --- a/futures-util/src/abortable.rs +++ b/futures-util/src/abortable.rs @@ -182,4 +182,17 @@ impl AbortHandle { self.inner.aborted.store(true, Ordering::Relaxed); self.inner.waker.wake(); } + + /// Checks whether [`AbortHandle::abort`] was *called* on any associated + /// [`AbortHandle`]s, which includes all the [`AbortHandle`]s linked with + /// the same [`AbortRegistration`]. This means that it will return `true` + /// even if: + /// * `abort` was called after the task had completed. + /// * `abort` was called while the task was being polled - the task may still be running and + /// will not be stopped until `poll` returns. + /// + /// This operation has a Relaxed ordering. + pub fn is_aborted(&self) -> bool { + self.inner.aborted.load(Ordering::Relaxed) + } }