Struct Abortable

#[must_use = "futures/streams do nothing unless you poll them"]
pub struct Abortable<T> { /* private fields */ }

A future/stream which can be remotely short-circuited using an AbortHandle.

Implementations

impl<T> Abortable<T>

fn new(task: T, reg: AbortRegistration) -> Self

Creates a new Abortable future/stream using an existing AbortRegistration. AbortRegistrations can be acquired through AbortHandle::new.

When abort is called on the handle tied to reg or if abort has already been called, the future/stream will complete immediately without making any further progress.

Examples:

Usage with futures:

# futures::executor::block_on(async {
use futures::future::{Abortable, AbortHandle, Aborted};

let (abort_handle, abort_registration) = AbortHandle::new_pair();
let future = Abortable::new(async { 2 }, abort_registration);
abort_handle.abort();
assert_eq!(future.await, Err(Aborted));
# });

Usage with streams:

# futures::executor::block_on(async {
# use futures::future::{Abortable, AbortHandle};
# use futures::stream::{self, StreamExt};

let (abort_handle, abort_registration) = AbortHandle::new_pair();
let mut stream = Abortable::new(stream::iter(vec![1, 2, 3]), abort_registration);
abort_handle.abort();
assert_eq!(stream.next().await, None);
# });
fn is_aborted(&self) -> bool

Checks whether the task has been aborted. Note that all this method indicates is whether AbortHandle::abort was called. 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.

Trait Implementations

impl<'__pin, T> Unpin for Abortable<T> where PinnedFieldsOf<__Origin<'__pin, T>>: Unpin,

impl<Fut> Future for Abortable<Fut> where Fut: Future,

type Output = Result<<Fut as Future>::Output, Aborted>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

impl<St> Stream for Abortable<St> where St: Stream,

type Item = <St as Stream>::Item;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>

impl<T: Clone> Clone for Abortable<T>

fn clone(&self) -> Abortable<T>

impl<T: Debug> Debug for Abortable<T>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl<T> !RefUnwindSafe for Abortable<T>

impl<T> !UnwindSafe for Abortable<T>

impl<T> Freeze for Abortable<T> where T: Freeze,

impl<T> Send for Abortable<T> where T: Send,

impl<T> Sync for Abortable<T> where T: Sync,

impl<T> UnsafeUnpin for Abortable<T> where T: UnsafeUnpin,

Blanket Implementations

impl<F> IntoFuture for Abortable<T> where F: Future,

type Output = <F as Future>::Output;
type IntoFuture = F;
fn into_future(self) -> <F as IntoFuture>::IntoFuture

impl<F, T, E> TryFuture for Abortable<T> where F: Future<Output = Result<T, E>> + ?Sized,

type Ok = T;
type Error = E;
fn try_poll(self: Pin<&mut F>, cx: &mut Context<'_>) -> Poll<<F as Future>::Output>

impl<Fut> TryFutureExt for Abortable<T> where Fut: TryFuture + ?Sized,

impl<S> TryStreamExt for Abortable<T> where S: TryStream + ?Sized,

impl<S, T, E> TryStream for Abortable<T> where S: Stream<Item = Result<T, E>> + ?Sized,

type Ok = T;
type Error = E;
fn try_poll_next(self: Pin<&mut S>, cx: &mut Context<'_>) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

impl<T> Any for Abortable<T> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Abortable<T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Abortable<T> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Abortable<T> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Abortable<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FutureExt for Abortable<T> where T: Future + ?Sized,

impl<T> StreamExt for Abortable<T> where T: Stream + ?Sized,

impl<T> ToOwned for Abortable<T> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Abortable<T> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Abortable<T> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Abortable<T> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>