diff options
Diffstat (limited to 'core/src/service/service_runner.rs')
| -rw-r--r-- | core/src/service/service_runner.rs | 31 |
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 |
