[][src]Trait futures_test::future::FutureTestExt

pub trait FutureTestExt: Future {
    fn assert_unmoved(self) -> AssertUnmoved<Self>
    where
        Self: Sized
, { ... }
fn pending_once(self) -> PendingOnce<Self>
    where
        Self: Sized
, { ... }
fn run_in_background(self)
    where
        Self: Sized + Send + 'static,
        Self::Output: Send
, { ... } }
[]

Additional combinators for testing futures.

Provided Methods

[]

Asserts that the given is not moved after being polled.

A check for movement is performed each time the future is polled and when Drop is called.

Aside from keeping track of the location at which the future was first polled and providing assertions, this future adds no runtime behavior and simply delegates to the child future.

[]

Introduces one Poll::Pending before polling the given future.

Examples

#![feature(async_await, futures_api, pin)]
use futures::task::Poll;
use futures::future::FutureExt;
use futures_test::task;
use futures_test::future::FutureTestExt;
use pin_utils::pin_mut;

let future = (async { 5 }).pending_once();
pin_mut!(future);

let cx = &mut task::no_spawn_context();

assert_eq!(future.poll_unpin(cx), Poll::Pending);
assert_eq!(future.poll_unpin(cx), Poll::Ready(5));

[]

Runs this future on a dedicated executor running in a background thread.

Examples

#![feature(async_await, futures_api, pin)]
use futures::channel::oneshot;
use futures::executor::block_on;
use futures_test::future::FutureTestExt;

let (tx, rx) = oneshot::channel::<i32>();

(async { tx.send(5).unwrap() }).run_in_background();

assert_eq!(block_on(rx), Ok(5));

Implementors