diff options
Diffstat (limited to 'vendor/futures-util/src/abortable.rs')
-rw-r--r-- | vendor/futures-util/src/abortable.rs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/vendor/futures-util/src/abortable.rs b/vendor/futures-util/src/abortable.rs index bb82dd0db..9dbcfc2b5 100644 --- a/vendor/futures-util/src/abortable.rs +++ b/vendor/futures-util/src/abortable.rs @@ -75,7 +75,18 @@ impl<T> Abortable<T> { /// in calls to `Abortable::new`. #[derive(Debug)] pub struct AbortRegistration { - inner: Arc<AbortInner>, + 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. @@ -100,9 +111,9 @@ impl AbortHandle { // Inner type storing the waker to awaken and a bool indicating that it // should be aborted. #[derive(Debug)] -struct AbortInner { - waker: AtomicWaker, - aborted: AtomicBool, +pub(crate) struct AbortInner { + pub(crate) waker: AtomicWaker, + pub(crate) aborted: AtomicBool, } /// Indicator that the `Abortable` task was aborted. @@ -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) + } } |