1use crate::{Executor, ExecutorBlocking, JoinHandle};
2use std::future::Future;
3
4#[derive(Clone, Copy, Debug, PartialOrd, PartialEq, Eq)]
9pub struct GlobalExecutor;
10
11impl Executor for GlobalExecutor {
12 #[cfg(all(feature = "tokio", not(target_arch = "wasm32")))]
13 fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
14 where
15 F: Future + Send + 'static,
16 F::Output: Send + 'static,
17 {
18 crate::rt::tokio::TokioExecutor.spawn(future)
19 }
20
21 #[cfg(all(feature = "threadpool", not(feature = "tokio")))]
22 fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
23 where
24 F: Future + Send + 'static,
25 F::Output: Send + 'static,
26 {
27 crate::rt::threadpool::ThreadPoolExecutor.spawn(future)
28 }
29
30 #[cfg(target_arch = "wasm32")]
31 fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
32 where
33 F: Future + Send + 'static,
34 F::Output: Send + 'static,
35 {
36 crate::rt::wasm::WasmExecutor.spawn(future)
37 }
38
39 #[cfg(all(
40 not(feature = "threadpool"),
41 not(feature = "tokio"),
42 not(target_arch = "wasm32")
43 ))]
44 fn spawn<F>(&self, _: F) -> JoinHandle<F::Output>
45 where
46 F: Future + Send + 'static,
47 F::Output: Send + 'static,
48 {
49 unreachable!()
50 }
51}
52
53impl ExecutorBlocking for GlobalExecutor {
54 #[cfg(all(feature = "tokio", not(target_arch = "wasm32")))]
55 fn spawn_blocking<F, R>(&self, f: F) -> JoinHandle<R>
56 where
57 F: FnOnce() -> R + Send + 'static,
58 R: Send + 'static,
59 {
60 crate::rt::tokio::TokioExecutor.spawn_blocking(f)
61 }
62
63 #[cfg(all(feature = "threadpool", not(feature = "tokio")))]
64 fn spawn_blocking<F, R>(&self, f: F) -> JoinHandle<R>
65 where
66 F: FnOnce() -> R + Send + 'static,
67 R: Send + 'static,
68 {
69 crate::rt::threadpool::ThreadPoolExecutor.spawn_blocking(f)
70 }
71
72 #[cfg(target_arch = "wasm32")]
73 fn spawn_blocking<F, R>(&self, f: F) -> JoinHandle<R>
74 where
75 F: FnOnce() -> R + Send + 'static,
76 R: Send + 'static,
77 {
78 crate::rt::wasm::WasmExecutor.spawn_blocking(f)
79 }
80
81 #[cfg(all(
82 not(feature = "threadpool"),
83 not(feature = "tokio"),
84 not(target_arch = "wasm32")
85 ))] fn spawn_blocking<F, R>(&self, _: F) -> JoinHandle<R>
86 where
87 F: FnOnce() -> R + Send + 'static,
88 R: Send + 'static,
89 {
90 unimplemented!()
91 }
92}
93