diff options
Diffstat (limited to 'tokio/src/runtime/handle.rs')
-rw-r--r-- | tokio/src/runtime/handle.rs | 41 |
1 files changed, 8 insertions, 33 deletions
diff --git a/tokio/src/runtime/handle.rs b/tokio/src/runtime/handle.rs index f8119e65..562a33ce 100644 --- a/tokio/src/runtime/handle.rs +++ b/tokio/src/runtime/handle.rs @@ -1,42 +1,29 @@ -use crate::runtime::{blocking, io, time}; +use crate::runtime::{blocking, io, time, Spawner}; cfg_rt_core! { - use crate::runtime::basic_scheduler; use crate::task::JoinHandle; use std::future::Future; } -cfg_rt_threaded! { - use crate::runtime::thread_pool; -} - /// Handle to the runtime #[derive(Debug, Clone)] pub struct Handle { - pub(super) kind: Kind, + pub(super) spawner: Spawner, /// Handles to the I/O drivers - pub(super) io_handles: Vec<io::Handle>, + pub(super) io_handle: io::Handle, /// Handles to the time drivers - pub(super) time_handles: Vec<time::Handle>, + pub(super) time_handle: time::Handle, + /// Source of `Instant::now()` pub(super) clock: time::Clock, /// Blocking pool spawner pub(super) blocking_spawner: blocking::Spawner, } -#[derive(Debug, Clone)] -pub(super) enum Kind { - Shell, - #[cfg(feature = "rt-core")] - Basic(basic_scheduler::Spawner), - #[cfg(feature = "rt-threaded")] - ThreadPool(thread_pool::Spawner), -} - impl Handle { /// Enter the runtime context pub fn enter<F, R>(&self, f: F) -> R @@ -44,15 +31,9 @@ impl Handle { F: FnOnce() -> R, { self.blocking_spawner.enter(|| { - let _io = io::set_default(&self.io_handles[0]); + let _io = io::set_default(&self.io_handle); - time::with_default(&self.time_handles[0], &self.clock, || match &self.kind { - Kind::Shell => f(), - #[cfg(feature = "rt-core")] - Kind::Basic(spawner) => spawner.enter(f), - #[cfg(feature = "rt-threaded")] - Kind::ThreadPool(spawner) => spawner.enter(f), - }) + time::with_default(&self.time_handle, &self.clock, || self.spawner.enter(f)) }) } } @@ -95,13 +76,7 @@ cfg_rt_core! { F: Future + Send + 'static, F::Output: Send + 'static, { - match &self.kind { - Kind::Shell => panic!("spawning not enabled for runtime"), - #[cfg(feature = "rt-core")] - Kind::Basic(spawner) => spawner.spawn(future), - #[cfg(feature = "rt-threaded")] - Kind::ThreadPool(spawner) => spawner.spawn(future), - } + self.spawner.spawn(future) } } } |