1use std::sync::mpsc::Sender;
2
3use dada_ir_ast::DebugEvent;
4use structopt::StructOpt;
5
6mod assets;
7mod error;
8mod events;
9mod hbs;
10mod root;
11mod server;
12mod source;
13mod view;
14
15#[derive(Debug, StructOpt)]
17pub struct DebugOptions {
18 #[structopt(long, default_value = "2222")]
19 pub port: u32,
20}
21
22impl DebugOptions {
23 pub fn to_server(&self) -> DebugServer {
25 DebugServer {
26 port: self.port,
27 thread: None,
28 }
29 }
30}
31
32pub struct DebugServer {
34 port: u32,
35 thread: Option<std::thread::JoinHandle<anyhow::Result<()>>>,
36}
37
38impl DebugServer {
39 pub fn launch(&mut self) -> Sender<DebugEvent> {
43 assert!(self.thread.is_none());
44 let (debug_tx, debug_rx) = std::sync::mpsc::channel();
45 let port = self.port;
46 self.thread = Some(std::thread::spawn(move || server::main(port, debug_rx)));
47 debug_tx
48 }
49
50 pub fn block_on(self) -> anyhow::Result<()> {
52 if let Some(thread) = self.thread {
53 thread.join().unwrap()?;
54 }
55 Ok(())
56 }
57}