summaryrefslogtreecommitdiffstats
path: root/vendor/tokio/src/runtime/spawner.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/tokio/src/runtime/spawner.rs')
-rw-r--r--vendor/tokio/src/runtime/spawner.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/tokio/src/runtime/spawner.rs b/vendor/tokio/src/runtime/spawner.rs
new file mode 100644
index 000000000..fbcde2cfa
--- /dev/null
+++ b/vendor/tokio/src/runtime/spawner.rs
@@ -0,0 +1,45 @@
+cfg_rt! {
+ use crate::future::Future;
+ use crate::runtime::basic_scheduler;
+ use crate::task::JoinHandle;
+}
+
+cfg_rt_multi_thread! {
+ use crate::runtime::thread_pool;
+}
+
+#[derive(Debug, Clone)]
+pub(crate) enum Spawner {
+ #[cfg(feature = "rt")]
+ Basic(basic_scheduler::Spawner),
+ #[cfg(feature = "rt-multi-thread")]
+ ThreadPool(thread_pool::Spawner),
+}
+
+impl Spawner {
+ pub(crate) fn shutdown(&mut self) {
+ #[cfg(feature = "rt-multi-thread")]
+ {
+ if let Spawner::ThreadPool(spawner) = self {
+ spawner.shutdown();
+ }
+ }
+ }
+}
+
+cfg_rt! {
+ impl Spawner {
+ pub(crate) fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
+ where
+ F: Future + Send + 'static,
+ F::Output: Send + 'static,
+ {
+ match self {
+ #[cfg(feature = "rt")]
+ Spawner::Basic(spawner) => spawner.spawn(future),
+ #[cfg(feature = "rt-multi-thread")]
+ Spawner::ThreadPool(spawner) => spawner.spawn(future),
+ }
+ }
+ }
+}