1 use futures_task::{FutureObj, Spawn, SpawnError};
2 
3 /// An implementation of [`Spawn`](futures_task::Spawn) that
4 /// discards spawned futures when used.
5 ///
6 /// # Examples
7 ///
8 /// ```
9 /// use futures::task::SpawnExt;
10 /// use futures_test::task::NoopSpawner;
11 ///
12 /// let spawner = NoopSpawner::new();
13 /// spawner.spawn(async { }).unwrap();
14 /// ```
15 #[derive(Debug)]
16 pub struct NoopSpawner {
17     _reserved: (),
18 }
19 
20 impl NoopSpawner {
21     /// Create a new instance
new() -> Self22     pub fn new() -> Self {
23         Self { _reserved: () }
24     }
25 }
26 
27 impl Spawn for NoopSpawner {
spawn_obj(&self, _future: FutureObj<'static, ()>) -> Result<(), SpawnError>28     fn spawn_obj(&self, _future: FutureObj<'static, ()>) -> Result<(), SpawnError> {
29         Ok(())
30     }
31 }
32 
33 impl Default for NoopSpawner {
default() -> Self34     fn default() -> Self {
35         Self::new()
36     }
37 }
38 
39 /// Get a reference to a singleton instance of [`NoopSpawner`].
40 ///
41 /// # Examples
42 ///
43 /// ```
44 /// use futures::task::SpawnExt;
45 /// use futures_test::task::noop_spawner_mut;
46 ///
47 /// let spawner = noop_spawner_mut();
48 /// spawner.spawn(async { }).unwrap();
49 /// ```
noop_spawner_mut() -> &'static mut NoopSpawner50 pub fn noop_spawner_mut() -> &'static mut NoopSpawner {
51     Box::leak(Box::new(NoopSpawner::new()))
52 }
53