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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::task::{panic_local_waker_ref, panic_spawner_mut};
use crate::task::{noop_local_waker_ref, noop_spawner_mut};
use futures_core::task::Context;

/// Create a new [`task::Context`](futures_core::task::Context) where both
/// the [waker](futures_core::task::Context::waker) and
/// [spawner](futures_core::task::Context::spawner) will panic if used.
///
/// # Examples
///
/// ```should_panic
/// #![feature(futures_api)]
/// use futures_test::task;
///
/// let cx = task::panic_context();
/// cx.waker().wake(); // Will panic
/// ```
pub fn panic_context() -> Context<'static> {
    Context::new(panic_local_waker_ref(), panic_spawner_mut())
}

/// Create a new [`task::Context`](futures_core::task::Context) where the
/// [waker](futures_core::task::Context::waker) will ignore any calls to
/// `wake` while the [spawner](futures_core::task::Context::spawner) will
/// panic if used.
///
/// # Examples
///
/// ```
/// #![feature(async_await, futures_api, pin)]
/// use futures::future::Future;
/// use futures::task::Poll;
/// use futures_test::task::no_spawn_context;
/// use pin_utils::pin_mut;
///
/// let mut future = async { 5 };
/// pin_mut!(future);
///
/// assert_eq!(future.poll(&mut no_spawn_context()), Poll::Ready(5));
/// ```
pub fn no_spawn_context() -> Context<'static> {
    Context::new(noop_local_waker_ref(), panic_spawner_mut())
}

/// Create a new [`task::Context`](futures_core::task::Context) where the
/// [waker](futures_core::task::Context::waker) and
/// [spawner](futures_core::task::Context::spawner) will both ignore any
/// uses.
///
/// # Examples
///
/// ```
/// #![feature(async_await, futures_api, pin)]
/// use futures::future::Future;
/// use futures::task::Poll;
/// use futures_test::task::noop_context;
/// use pin_utils::pin_mut;
///
/// let mut future = async { 5 };
/// pin_mut!(future);
///
/// assert_eq!(future.poll(&mut noop_context()), Poll::Ready(5));
/// ```
pub fn noop_context() -> Context<'static> {
    Context::new(noop_local_waker_ref(), noop_spawner_mut())
}