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