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
impl TestAsyncExecutor
Sourcepub fn new() -> GenericArc<Self>
pub fn new() -> GenericArc<Self>
Create a new TestAsyncExecutor instance.
Sourcepub fn spawn<F: Future + Send + 'static>(
this: &GenericArc<Self>,
f: F,
) -> TestAsyncExecutorTaskWaiter<F::Output> ⓘ
pub fn spawn<F: Future + Send + 'static>( this: &GenericArc<Self>, f: F, ) -> TestAsyncExecutorTaskWaiter<F::Output> ⓘ
Enqueue a top-level Future for polling from a subsequent
run_to_completion() invocation.
§See also:
Sourcepub fn run_to_completion(this: &GenericArc<Self>)
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.