Struct Abortable

struct Abortable<T> { ... }

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: &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.

impl<'__pin, T> Unpin for Abortable<T>

impl<F> IntoFuture for Abortable<T>

fn into_future(self: Self) -> <F as IntoFuture>::IntoFuture

impl<F, T, E> TryFuture for Abortable<T>

fn try_poll(self: Pin<&mut F>, cx: &mut Context<'_>) -> Poll<<F as Future>::Output>

impl<Fut> Future for Abortable<Fut>

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<<Self as >::Output>

impl<Fut> TryFutureExt for Abortable<T>

impl<S> TryStreamExt for Abortable<T>

impl<S, T, E> TryStream for Abortable<T>

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

impl<St> Stream for Abortable<St>

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

impl<T> Any for Abortable<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Abortable<T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Abortable<T>

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

impl<T> CloneToUninit for Abortable<T>

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

impl<T> Freeze for Abortable<T>

impl<T> From for Abortable<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FutureExt for Abortable<T>

impl<T> RefUnwindSafe for Abortable<T>

impl<T> Send for Abortable<T>

impl<T> StreamExt for Abortable<T>

impl<T> Sync for Abortable<T>

impl<T> ToOwned for Abortable<T>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> UnsafeUnpin for Abortable<T>

impl<T> UnwindSafe for Abortable<T>

impl<T, U> Into for Abortable<T>

fn into(self: 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 for Abortable<T>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Abortable<T>

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

impl<T: $crate::clone::Clone> Clone for Abortable<T>

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

impl<T: $crate::fmt::Debug> Debug for Abortable<T>

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