• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 cfg_rt! {
2     use crate::runtime::basic_scheduler;
3     use crate::task::JoinHandle;
4 
5     use std::future::Future;
6 }
7 
8 cfg_rt_multi_thread! {
9     use crate::runtime::thread_pool;
10 }
11 
12 #[derive(Debug, Clone)]
13 pub(crate) enum Spawner {
14     #[cfg(feature = "rt")]
15     Basic(basic_scheduler::Spawner),
16     #[cfg(feature = "rt-multi-thread")]
17     ThreadPool(thread_pool::Spawner),
18 }
19 
20 impl Spawner {
shutdown(&mut self)21     pub(crate) fn shutdown(&mut self) {
22         #[cfg(feature = "rt-multi-thread")]
23         {
24             if let Spawner::ThreadPool(spawner) = self {
25                 spawner.shutdown();
26             }
27         }
28     }
29 }
30 
31 cfg_rt! {
32     impl Spawner {
33         pub(crate) fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
34         where
35             F: Future + Send + 'static,
36             F::Output: Send + 'static,
37         {
38             match self {
39                 #[cfg(feature = "rt")]
40                 Spawner::Basic(spawner) => spawner.spawn(future),
41                 #[cfg(feature = "rt-multi-thread")]
42                 Spawner::ThreadPool(spawner) => spawner.spawn(future),
43             }
44         }
45     }
46 }
47