From e43e64abb1f74ab519d1a2f8ce61014e012e5988 Mon Sep 17 00:00:00 2001 From: ZhennanWu Date: Fri, 17 Feb 2023 17:58:54 -0800 Subject: [PATCH 1/4] add AbortHandle::is_aborted() --- futures-util/src/abortable.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/futures-util/src/abortable.rs b/futures-util/src/abortable.rs index e0afd47218..bf3fb4c696 100644 --- a/futures-util/src/abortable.rs +++ b/futures-util/src/abortable.rs @@ -182,4 +182,13 @@ 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 operation has a Relaxed ordering. + pub fn is_aborted(&self) -> bool { + self.inner.aborted.load(Ordering::Relaxed) + } } From 46fa1ed5be88d100246a6f2a7fba8d3c00af54a9 Mon Sep 17 00:00:00 2001 From: ZhennanWu <38578020+ZhennanWu@users.noreply.github.com> Date: Fri, 17 Feb 2023 18:13:17 -0800 Subject: [PATCH 2/4] Address cargo fmt issue --- futures-util/src/abortable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/futures-util/src/abortable.rs b/futures-util/src/abortable.rs index bf3fb4c696..c98c033aad 100644 --- a/futures-util/src/abortable.rs +++ b/futures-util/src/abortable.rs @@ -186,7 +186,7 @@ impl AbortHandle { /// Checks whether [`AbortHandle::abort`] was *called* on any associated /// [`AbortHandle`]s, which includes all the [`AbortHandle`]s linked with /// the same [`AbortRegistration`]. - /// + /// /// This operation has a Relaxed ordering. pub fn is_aborted(&self) -> bool { self.inner.aborted.load(Ordering::Relaxed) From 92b0cf47623967c822e235fcf370d16df4f88044 Mon Sep 17 00:00:00 2001 From: ZhennanWu <38578020+ZhennanWu@users.noreply.github.com> Date: Fri, 17 Feb 2023 18:14:41 -0800 Subject: [PATCH 3/4] Address cargo fmt issue #2 --- futures-util/src/abortable.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/futures-util/src/abortable.rs b/futures-util/src/abortable.rs index c98c033aad..a46fb7c36f 100644 --- a/futures-util/src/abortable.rs +++ b/futures-util/src/abortable.rs @@ -183,8 +183,8 @@ impl AbortHandle { self.inner.waker.wake(); } - /// Checks whether [`AbortHandle::abort`] was *called* on any associated - /// [`AbortHandle`]s, which includes all the [`AbortHandle`]s linked with + /// Checks whether [`AbortHandle::abort`] was *called* on any associated + /// [`AbortHandle`]s, which includes all the [`AbortHandle`]s linked with /// the same [`AbortRegistration`]. /// /// This operation has a Relaxed ordering. From c78ff065c40b5c50c8d7d0623e432728dbd1514d Mon Sep 17 00:00:00 2001 From: ZhennanWu <38578020+ZhennanWu@users.noreply.github.com> Date: Sat, 18 Feb 2023 17:34:27 -0800 Subject: [PATCH 4/4] Mention caveat, address review --- futures-util/src/abortable.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/futures-util/src/abortable.rs b/futures-util/src/abortable.rs index a46fb7c36f..cb81ce32cd 100644 --- a/futures-util/src/abortable.rs +++ b/futures-util/src/abortable.rs @@ -185,7 +185,11 @@ impl AbortHandle { /// Checks whether [`AbortHandle::abort`] was *called* on any associated /// [`AbortHandle`]s, which includes all the [`AbortHandle`]s linked with - /// the same [`AbortRegistration`]. + /// 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 {