tweak
This commit is contained in:
parent
f1864ad7b0
commit
30d7a487d6
1 changed files with 6 additions and 14 deletions
|
@ -2,7 +2,7 @@ use std::{
|
|||
collections::HashMap,
|
||||
io::{BufRead, Write},
|
||||
sync::{
|
||||
atomic::{AtomicU64, AtomicUsize, Ordering},
|
||||
atomic::{AtomicU64, Ordering},
|
||||
mpsc::{channel, Receiver, Sender},
|
||||
Arc, Mutex, OnceLock,
|
||||
},
|
||||
|
@ -16,15 +16,11 @@ use serde_json::Value;
|
|||
|
||||
pub mod kv;
|
||||
|
||||
pub type DynNode = Arc<Mutex<dyn Node>>;
|
||||
pub type NodeyNodeFace = Arc<Mutex<dyn Node>>;
|
||||
pub type OnInit = Box<dyn Fn(&Runner)>;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, ErrorCode>;
|
||||
|
||||
pub type RpcPromise = Receiver<Message>;
|
||||
|
||||
static MSG_ID: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
pub trait Node {
|
||||
fn handle(&mut self, runner: &Runner, msg: Message);
|
||||
}
|
||||
|
@ -62,23 +58,21 @@ impl Network {
|
|||
}
|
||||
|
||||
pub struct Runner {
|
||||
node: DynNode,
|
||||
node: NodeyNodeFace,
|
||||
node_id: OnceLock<String>,
|
||||
nodes: OnceLock<Vec<String>>,
|
||||
network: OnceLock<Network>,
|
||||
backdoor: OnceLock<Sender<Message>>,
|
||||
steps: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
impl Runner {
|
||||
pub fn new(node: DynNode) -> Self {
|
||||
pub fn new(node: NodeyNodeFace) -> Self {
|
||||
Runner {
|
||||
node,
|
||||
nodes: OnceLock::new(),
|
||||
node_id: OnceLock::new(),
|
||||
network: OnceLock::new(),
|
||||
backdoor: OnceLock::new(),
|
||||
steps: Arc::new(AtomicUsize::new(0)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,10 +169,6 @@ impl Runner {
|
|||
self.nodes.get().unwrap()
|
||||
}
|
||||
|
||||
pub fn steps(&self) -> usize {
|
||||
self.steps.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
pub fn init(&self, msg: &Message) {
|
||||
let node_id = msg
|
||||
.body
|
||||
|
@ -245,3 +235,5 @@ pub fn mk_payload(payload: &[(&str, Value)]) -> Payload {
|
|||
.map(|p| (p.0.to_string(), p.1.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
static MSG_ID: AtomicU64 = AtomicU64::new(0);
|
||||
|
|
Loading…
Reference in a new issue