summary refs log tree commit diff
path: root/src/main.rs
blob: a63c4bda47bc20453cf8ed3a57047bf0394c1dc5 (plain)
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
mod config;
mod system;

use std::thread::{self, JoinHandle};
use tokio::runtime;

use system::System;

fn main() {
    let config_str = include_str!("../config.toml");
    let config = config::Config::load(config_str.to_string());

    let handles : Vec<_> = config.systems.into_iter().map(|(system_name, system_config)| -> JoinHandle<()>  {
        println!("Starting thread for system {}", system_name);
        thread::spawn(move || {
            let runtime = runtime::Builder::new_current_thread().enable_all().build().expect("Could not construct Tokio runtime");
            runtime.block_on(async {
                let mut system = System::new(system_config);
                system.start_clients().await;
            })
        })
    }).collect();

    for thread_handle in handles.into_iter() {
        thread_handle.join().expect("Child thread has panicked");
    }
}