aboutsummaryrefslogtreecommitdiff
path: root/src/abortable.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/abortable.rs')
-rw-r--r--src/abortable.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/abortable.rs b/src/abortable.rs
index e0afd47..9dbcfc2 100644
--- a/src/abortable.rs
+++ b/src/abortable.rs
@@ -78,6 +78,17 @@ pub struct AbortRegistration {
pub(crate) inner: Arc<AbortInner>,
}
+impl AbortRegistration {
+ /// Create an [`AbortHandle`] from the given [`AbortRegistration`].
+ ///
+ /// The created [`AbortHandle`] is functionally the same as any other
+ /// [`AbortHandle`]s that are associated with the same [`AbortRegistration`],
+ /// such as the one created by [`AbortHandle::new_pair`].
+ pub fn handle(&self) -> AbortHandle {
+ AbortHandle { inner: self.inner.clone() }
+ }
+}
+
/// A handle to an `Abortable` task.
#[derive(Debug, Clone)]
pub struct AbortHandle {
@@ -182,4 +193,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)
+ }
}