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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use crate::common::{Result, Text};
use crate::config::Config;
use crate::data_input;
use crate::engine;
use crate::events::Event;
use crate::person_input;
use crate::screen;
use async_std::channel::{self, Receiver, Sender};
use async_std::io;
use async_std::task;
const CHANNEL_SIZE: usize = 1024;
pub async fn run<R, I, W>(config: Config, stdin: R, inbox: I, outbox: W) -> Result<Option<Text>>
where
R: io::Read + Send + Unpin + 'static,
I: io::Read + Send + Unpin + 'static,
W: io::Write + Send + Unpin + 'static,
{
let (input_sender, input_recv) = channel();
let (output_sender, output_recv) = channel();
let screen_task = task::spawn(screen::task(config.clone(), outbox, output_recv));
let person_task = task::spawn(person_input::task(
config,
inbox,
input_sender.clone(),
output_sender.clone(),
));
let engine_task = task::spawn(engine::task(input_recv, output_sender));
let data_task = task::spawn(data_input::task(stdin, input_sender));
let selection = screen_task.await;
drop(data_task);
drop(person_task);
drop(engine_task);
selection
}
fn channel() -> (Sender<Event>, Receiver<Event>) {
channel::bounded::<Event>(CHANNEL_SIZE)
}