aboutsummaryrefslogtreecommitdiff
path: root/core/src/service/service_runner.rs
blob: bd2d1d92d2c23a8905402e9292fe81f275e05b34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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");
            }
        });
    }
}