[][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

Important traits for AssertUnmoved<Fut>
fn assert_unmoved(self) -> AssertUnmoved<Self> where
    Self: Sized

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.

Important traits for PendingOnce<Fut>
fn pending_once(self) -> PendingOnce<Self> where
    Self: Sized

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

Examples

#![feature(async_await, futures_api)]
use futures::task::{Context, 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 mut cx = Context::from_waker(task::noop_waker_ref());

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

fn run_in_background(self) where
    Self: Sized + Send + 'static,
    Self::Output: Send

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

Examples

#![feature(async_await, futures_api)]
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));
Loading content...

Implementors

impl<Fut> FutureTestExt for Fut where
    Fut: Future
[src]

Important traits for AssertUnmoved<Fut>
fn assert_unmoved(self) -> AssertUnmoved<Self> where
    Self: Sized
[src]

Important traits for PendingOnce<Fut>
fn pending_once(self) -> PendingOnce<Self> where
    Self: Sized
[src]

fn run_in_background(self) where
    Self: Sized + Send + 'static,
    Self::Output: Send
[src]

Loading content...