-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abortable streams #2410
Abortable streams #2410
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This looks good to me!
Is there a better place to put
Abortable
thanfutures-util/src/abortable.rs
? Maybe ashared/
folder?
shared/
is confusing with future/shared
, so I think futures-util/src/abortable.rs
is fine.
futures-util/src/abortable.rs
Outdated
/// # use futures::stream::{self, StreamExt}; | ||
/// | ||
/// let (abort_handle, abort_registration) = AbortHandle::new_pair(); | ||
/// let mut stream = Abortable::stream(stream::iter(vec![1, 2, 3]), abort_registration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't seem to exist, but I think it's not actually a bad idea to have both Abortable::new
(require T: Future
) and Abortable::stream
(require T: Stream
) because we can prevent the creation of Abortables that cannot be polled. -- However, it may feel redundant when we provide other abortables (e.g., abortable sink) in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I wrote Abortable::new
and stream
, but I thought that new
for abortable futures specifically was a bit arbitrary.
futures-util/src/abortable.rs
Outdated
/// Checks whether the task has been aborted. See [`AbortHandle::abort`] for details. | ||
pub fn is_aborted(&self) -> bool { | ||
self.inner.aborted.load(Ordering::Relaxed) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually a method that returns true if it is notified that the task should be aborted (= abort
was called), and I think there are some notes that are desirable to explain in the documentation.
- This will return true even if
abort
is called after the task has completed. - This will return true even if the task still is running at the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we can omit is_aborted
method until someone actually requests it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might as well keep it, because we can use it internally in try_poll
instead of loading the flag manually. I'll update the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the docs, is Ordering::Relaxed
enough for the user facing API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. LGTM aside from a nit.
Co-authored-by: Taiki Endo <te316e89@gmail.com>
This PR makes
Abortable
able to work with both futures and streams.Is there a better place to put
Abortable
thanfutures-util/src/abortable.rs
? Maybe ashared/
folder?Resolves #1424