futures_test/task/
context.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::task::{noop_waker_ref, panic_waker_ref};
use futures_core::task::Context;

/// Create a new [`Context`](core::task::Context) where the
/// [waker](core::task::Context::waker) will panic if used.
///
/// # Examples
///
/// ```should_panic
/// use futures_test::task::panic_context;
///
/// let cx = panic_context();
/// cx.waker().wake_by_ref(); // Will panic
/// ```
pub fn panic_context() -> Context<'static> {
    Context::from_waker(panic_waker_ref())
}

/// Create a new [`Context`](core::task::Context) where the
/// [waker](core::task::Context::waker) will ignore any uses.
///
/// # Examples
///
/// ```
/// use futures::future::Future;
/// use futures::task::Poll;
/// use futures_test::task::noop_context;
/// use futures::pin_mut;
///
/// let future = async { 5 };
/// pin_mut!(future);
///
/// assert_eq!(future.poll(&mut noop_context()), Poll::Ready(5));
/// ```
pub fn noop_context() -> Context<'static> {
    Context::from_waker(noop_waker_ref())
}