tracing_futures/executor/futures_03.rs
1use crate::{Instrument, Instrumented, WithDispatch};
2use futures_task::{FutureObj, LocalFutureObj, LocalSpawn, Spawn, SpawnError};
3
4impl<T> Spawn for Instrumented<T>
5where
6 T: Spawn,
7{
8 /// Spawns a future that will be run to completion.
9 ///
10 /// # Errors
11 ///
12 /// The executor may be unable to spawn tasks. Spawn errors should
13 /// represent relatively rare scenarios, such as the executor
14 /// having been shut down so that it is no longer able to accept
15 /// tasks.
16 fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> {
17 let future = future.instrument(self.span.clone());
18 self.inner.spawn_obj(FutureObj::new(Box::new(future)))
19 }
20
21 /// Determines whether the executor is able to spawn new tasks.
22 ///
23 /// This method will return `Ok` when the executor is *likely*
24 /// (but not guaranteed) to accept a subsequent spawn attempt.
25 /// Likewise, an `Err` return means that `spawn` is likely, but
26 /// not guaranteed, to yield an error.
27 #[inline]
28 fn status(&self) -> Result<(), SpawnError> {
29 self.inner.status()
30 }
31}
32
33impl<T> Spawn for WithDispatch<T>
34where
35 T: Spawn,
36{
37 /// Spawns a future that will be run to completion.
38 ///
39 /// # Errors
40 ///
41 /// The executor may be unable to spawn tasks. Spawn errors should
42 /// represent relatively rare scenarios, such as the executor
43 /// having been shut down so that it is no longer able to accept
44 /// tasks.
45 fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> {
46 self.inner
47 .spawn_obj(FutureObj::new(Box::new(self.with_dispatch(future))))
48 }
49
50 /// Determines whether the executor is able to spawn new tasks.
51 ///
52 /// This method will return `Ok` when the executor is *likely*
53 /// (but not guaranteed) to accept a subsequent spawn attempt.
54 /// Likewise, an `Err` return means that `spawn` is likely, but
55 /// not guaranteed, to yield an error.
56 #[inline]
57 fn status(&self) -> Result<(), SpawnError> {
58 self.inner.status()
59 }
60}
61
62impl<T> LocalSpawn for Instrumented<T>
63where
64 T: LocalSpawn,
65{
66 /// Spawns a future that will be run to completion.
67 ///
68 /// # Errors
69 ///
70 /// The executor may be unable to spawn tasks. Spawn errors should
71 /// represent relatively rare scenarios, such as the executor
72 /// having been shut down so that it is no longer able to accept
73 /// tasks.
74 fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> {
75 let future = future.instrument(self.span.clone());
76 self.inner
77 .spawn_local_obj(LocalFutureObj::new(Box::new(future)))
78 }
79
80 /// Determines whether the executor is able to spawn new tasks.
81 ///
82 /// This method will return `Ok` when the executor is *likely*
83 /// (but not guaranteed) to accept a subsequent spawn attempt.
84 /// Likewise, an `Err` return means that `spawn` is likely, but
85 /// not guaranteed, to yield an error.
86 #[inline]
87 fn status_local(&self) -> Result<(), SpawnError> {
88 self.inner.status_local()
89 }
90}
91
92impl<T> LocalSpawn for WithDispatch<T>
93where
94 T: LocalSpawn,
95{
96 /// Spawns a future that will be run to completion.
97 ///
98 /// # Errors
99 ///
100 /// The executor may be unable to spawn tasks. Spawn errors should
101 /// represent relatively rare scenarios, such as the executor
102 /// having been shut down so that it is no longer able to accept
103 /// tasks.
104 fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> {
105 self.inner
106 .spawn_local_obj(LocalFutureObj::new(Box::new(self.with_dispatch(future))))
107 }
108
109 /// Determines whether the executor is able to spawn new tasks.
110 ///
111 /// This method will return `Ok` when the executor is *likely*
112 /// (but not guaranteed) to accept a subsequent spawn attempt.
113 /// Likewise, an `Err` return means that `spawn` is likely, but
114 /// not guaranteed, to yield an error.
115 #[inline]
116 fn status_local(&self) -> Result<(), SpawnError> {
117 self.inner.status_local()
118 }
119}