Skip to main content

TestAsyncExecutor

Struct TestAsyncExecutor 

Source
pub struct TestAsyncExecutor { /* private fields */ }
Expand description

Single-threaded Future task executor for testing purposes.

Enqueue top-level Futures via spawn() and poll all currently enqueued ones to completion via run_to_completion().

Enqueued Futures may enqueue further ones from their Future::poll() and poll on the resulting TestAsyncExecutorTaskWaiter.

Implementations§

Source§

impl TestAsyncExecutor

Source

pub fn new() -> GenericArc<Self>

Create a new TestAsyncExecutor instance.

Source

pub fn spawn<F: Future + Send + 'static>( this: &GenericArc<Self>, f: F, ) -> TestAsyncExecutorTaskWaiter<F::Output>
where F::Output: Send + 'static,

Enqueue a top-level Future for polling from a subsequent run_to_completion() invocation.

§See also:
Source

pub fn run_to_completion(this: &GenericArc<Self>)

Poll all currently enqueued Futures to completion.

A Future is in “runnable” state right after it has been enqueued and ceases to once its Future::poll() returns a status of Pending. A non-runnable Future becomes runnable again when woken. There must always be at least one runnable Future left, or the executor will become stuck and report the fact via a panic.

run_to_completion() polls the runnable enqueued Future in a round-robin fashion, in the order of their enqueueing. That is, if futures [a, b, c] are enqueued, with a non-runnable and b and c runnable, and the cursor is at a or b, then b will get polled first, followed by c, followed by a if that became runnable in the course of polling b or c.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.