Restructuring tokio tasks and stdin receiver
This commit is contained in:
@@ -8,6 +8,7 @@ pub(crate) struct SideNode {
|
||||
crdt: BaseCrdt<TransactionList>,
|
||||
keys: fastcrypto::ed25519::Ed25519KeyPair,
|
||||
incoming_receiver: mpsc::Receiver<SignedOp>,
|
||||
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
||||
}
|
||||
|
||||
impl SideNode {
|
||||
@@ -15,25 +16,37 @@ impl SideNode {
|
||||
crdt: BaseCrdt<TransactionList>,
|
||||
keys: Ed25519KeyPair,
|
||||
incoming_receiver: mpsc::Receiver<SignedOp>,
|
||||
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
||||
) -> Self {
|
||||
let node = Self {
|
||||
crdt,
|
||||
keys,
|
||||
incoming_receiver,
|
||||
stdin_receiver,
|
||||
};
|
||||
node
|
||||
}
|
||||
|
||||
pub(crate) async fn start(&mut self) {
|
||||
println!("Starting node...");
|
||||
|
||||
loop {
|
||||
let incoming = self.incoming_receiver.recv().await.unwrap();
|
||||
println!("Received incoming message: {:?}", incoming);
|
||||
self.handle_incoming(incoming);
|
||||
match self.stdin_receiver.try_recv() {
|
||||
Ok(stdin) => {
|
||||
println!("Received stdin input: {:?}", stdin);
|
||||
}
|
||||
Err(_) => {}
|
||||
}
|
||||
match self.incoming_receiver.try_recv() {
|
||||
Ok(incoming) => {
|
||||
self.handle_incoming(&incoming);
|
||||
}
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_incoming(&mut self, incoming: SignedOp) {
|
||||
fn handle_incoming(&mut self, incoming: &SignedOp) {
|
||||
println!("WINNNINGINGINGINGINGIGNIGN");
|
||||
self.crdt.apply(incoming.clone());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user