futures_test/task/mod.rs
1// TODO: note that paths like futures_core::task::Context actually get redirected to core::task::Context
2// in the redered docs. Is this desirable? If so, should we change the paths here?
3//
4// Also, there is cross crate links in here. They are not going to work anytime soon. Do we put https links
5// in here? to here: https://rust-lang-nursery.github.io/futures-api-docs? The problem is these have a
6// version hardcoded in the url: 0.3.0-alpha.16 We could link to docs.rs, but currently that says:
7// docs.rs failed to build futures-preview-0.3.0-alpha.16 -> ok the reason seems to be that they are on
8// 2019-04-17 which does still have futures-api unstable feature, so that should get solved.
9//
10//! Task related testing utilities.
11//!
12//! This module provides utilities for creating test
13//! [`Context`](futures_core::task::Context)s,
14//! [`Waker`](futures_core::task::Waker)s and
15//! [`Spawn`](futures_core::task::Spawn) implementations.
16//!
17//! Test contexts:
18//! - [`noop_context`](crate::task::noop_context) creates a context that ignores calls to
19//! [`cx.waker().wake_by_ref()`](futures_core::task::Waker).
20//! - [`panic_context`](crate::task::panic_context) creates a context that panics when
21//! [`cx.waker().wake_by_ref()`](futures_core::task::Waker) is called.
22//!
23//! Test wakers:
24//! - [`noop_waker`](crate::task::noop_waker) creates a waker that ignores calls to
25//! [`wake`](futures_core::task::Waker).
26//! - [`panic_waker`](crate::task::panic_waker::panic_waker) creates a waker that panics when
27//! [`wake`](futures_core::task::Waker) is called.
28//! - [`new_count_waker`](crate::task::new_count_waker) creates a waker that increments a counter whenever
29//! [`wake`](futures_core::task::Waker) is called.
30//!
31//! Test spawners:
32//! - [`NoopSpawner`](crate::task::NoopSpawner) ignores calls to
33//! [`spawn`](futures_util::task::SpawnExt::spawn)
34//! - [`PanicSpawner`](crate::task::PanicSpawner) panics if [`spawn`](futures_util::task::SpawnExt::spawn) is
35//! called.
36//! - [`RecordSpawner`](crate::task::RecordSpawner) records the spawned futures.
37//!
38//! For convenience there additionally exist various functions that directly
39//! return waker/spawner references: [`noop_waker_ref`](crate::task::noop_waker_ref),
40//! [`panic_waker_ref`](crate::task::panic_waker_ref), [`noop_spawner_mut`](crate::task::noop_spawner_mut) and [`panic_spawner_mut`](crate::task::panic_spawner_mut).
41
42mod context;
43pub use self::context::{noop_context, panic_context};
44
45mod noop_spawner;
46pub use self::noop_spawner::{noop_spawner_mut, NoopSpawner};
47
48pub use futures_util::task::{noop_waker, noop_waker_ref};
49
50mod panic_spawner;
51pub use self::panic_spawner::{panic_spawner_mut, PanicSpawner};
52
53mod panic_waker;
54pub use self::panic_waker::{panic_waker, panic_waker_ref};
55
56mod record_spawner;
57pub use self::record_spawner::RecordSpawner;
58
59mod wake_counter;
60pub use self::wake_counter::{AwokenCount, new_count_waker};