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
mod dfa;
use dfa::Automaton;
use futures::channel::mpsc::{self, Receiver, Sender};
use futures::stream::StreamExt;
pub struct Raft<Message, State, Process>
where
Message: Clone + Send,
State: Default,
Process: FnMut(Message, State) -> State,
{
automaton: Automaton<Message>,
send_out: Sender<Message>,
recv_in: Receiver<Message>,
process_state: State,
process: Process,
}
impl<Message, State, Process> Raft<Message, State, Process>
where
Message: Clone + Send,
State: Default,
Process: FnMut(Message, State) -> State,
{
pub fn new(
id: [u8; 24],
n: usize,
p: Process,
) -> (
Raft<Message, State, Process>,
Sender<Message>,
Receiver<Message>,
) {
let (send_in, recv_in) = mpsc::channel(n);
let (send_out, recv_out) = mpsc::channel(n);
let r = Raft {
automaton: Automaton::new(id.into(), n),
send_out,
recv_in,
process_state: Default::default(),
process: p,
};
(r, send_in, recv_out)
}
pub async fn run(mut self) {
while let Some(_m) = self.recv_in.next().await {
unimplemented!();
}
}
}