From 1fad4ab3b3c5adeae27817acac5f4425f36d953a Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 9 Sep 2022 21:39:39 +0400 Subject: [PATCH] Improve `StopFlag`'s implementation Former-commit-id: 0807eb57e15e2ea00b14392dde22e917e04d6a19 --- src/stop.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/stop.rs b/src/stop.rs index 4fdfc478..f61caf3d 100644 --- a/src/stop.rs +++ b/src/stop.rs @@ -5,7 +5,7 @@ //! [flag]: StopFlag //! [listeners]: crate::dispatching::update_listeners -use std::{future::Future, pin::Pin, task}; +use std::{convert::Infallible, future::Future, pin::Pin, task}; use futures::future::{pending, AbortHandle, Abortable, Pending}; @@ -31,7 +31,7 @@ pub struct StopToken(AbortHandle); /// [`is_stopped`]: StopFlag::is_stopped #[pin_project::pin_project] #[derive(Clone)] -pub struct StopFlag(#[pin] Abortable>); +pub struct StopFlag(#[pin] Abortable>); impl StopToken { /// "Stops" the flag associated with this token. @@ -56,12 +56,9 @@ impl Future for StopFlag { type Output = (); fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll { - self.project().0.poll(cx).map(|res| { - debug_assert!( - res.is_err(), - "Pending Future can't ever be resolved, so Abortable is only resolved when \ - canceled" - ); + self.project().0.poll(cx).map(|res| match res { + Err(_aborted) => (), + Ok(unreachable) => match unreachable {}, }) } }