aboutsummaryrefslogtreecommitdiff
path: root/core/src/service/service_runner.rs
diff options
context:
space:
mode:
author1992414357@qq.com <1992414357@qq.com>2025-06-09 01:44:36 +0800
committer1992414357@qq.com <1992414357@qq.com>2025-06-09 01:44:36 +0800
commit49192dbb98e0ab1f2a66b4786fac86d63f69be64 (patch)
tree7cdf27c7cab5fb6b1aabc2ac7c44b7b492558945 /core/src/service/service_runner.rs
parentc9dbba0d288becb7f05cebe526be25c76e5a850a (diff)
重构所有部分
Diffstat (limited to 'core/src/service/service_runner.rs')
-rw-r--r--core/src/service/service_runner.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/src/service/service_runner.rs b/core/src/service/service_runner.rs
new file mode 100644
index 0000000..bd2d1d9
--- /dev/null
+++ b/core/src/service/service_runner.rs
@@ -0,0 +1,31 @@
+use std::pin::Pin;
+use crate::service::tcp_network::utils::tokio_utils::build_tokio_runtime;
+use tokio::spawn;
+
+#[macro_export]
+#[allow(unused_macros)]
+macro_rules! run_services {
+ ($($service:expr),+ $(,)?) => {
+ nogamepads_core::service::service_runner::ServiceRunner::run(Vec::from([$($service),+]));
+ };
+}
+
+pub type NoGamepadsService = Pin<Box<dyn Future<Output = ()> + Send>>;
+
+pub struct ServiceRunner;
+
+impl ServiceRunner {
+ pub fn run(futures: Vec<NoGamepadsService>) {
+ let runtime = build_tokio_runtime("nogamepads".to_string());
+ runtime.block_on(async {
+ let mut handles = Vec::new();
+ for fut in futures {
+ handles.push(spawn(fut));
+ }
+
+ for handle in handles {
+ handle.await.expect("Task panicked");
+ }
+ });
+ }
+} \ No newline at end of file