Simplifying
This commit is contained in:
@@ -4,19 +4,18 @@ use ezsockets::ClientConfig;
|
||||
use std::io::BufRead;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::{node::SideNode, utils};
|
||||
use crate::utils;
|
||||
|
||||
pub(crate) struct WebSocketClient {
|
||||
incoming_sender: mpsc::Sender<SignedOp>,
|
||||
}
|
||||
|
||||
impl WebSocketClient {
|
||||
pub(crate) fn new(incoming_sender: mpsc::Sender<SignedOp>) -> Self {
|
||||
Self { incoming_sender }
|
||||
}
|
||||
|
||||
/// Start the websocket client
|
||||
pub(crate) async fn start(node: &mut SideNode, incoming_sender: mpsc::Sender<SignedOp>) {
|
||||
pub(crate) async fn start(
|
||||
incoming_sender: mpsc::Sender<SignedOp>,
|
||||
// stdin_sender: mpsc::Sender<String>,
|
||||
) -> tokio::task::JoinHandle<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
let config = ClientConfig::new("ws://localhost:8080/websocket");
|
||||
let (handle, future) =
|
||||
@@ -24,24 +23,27 @@ impl WebSocketClient {
|
||||
tokio::spawn(async move {
|
||||
future.await.unwrap();
|
||||
});
|
||||
let stdin = std::io::stdin();
|
||||
let lines = stdin.lock().lines();
|
||||
for line in lines {
|
||||
println!("We don't get here until we send a message");
|
||||
let line = line.unwrap();
|
||||
let signed_op = if let "exit" = line.as_str() {
|
||||
break;
|
||||
} else if let "trace" = line.as_str() {
|
||||
node.trace_crdt();
|
||||
continue;
|
||||
} else {
|
||||
let fake = utils::fake_transaction("foo123".to_string());
|
||||
node.add_transaction_local(fake)
|
||||
};
|
||||
tracing::info!("sending {:?}", signed_op);
|
||||
let json = serde_json::to_string(&signed_op).unwrap();
|
||||
handle.text(json).unwrap();
|
||||
}
|
||||
tokio::spawn(async move {
|
||||
let stdin = std::io::stdin();
|
||||
let lines = stdin.lock().lines();
|
||||
for line in lines {
|
||||
println!("We don't get here until we send a message");
|
||||
let line = line.unwrap();
|
||||
let signed_op = if let "exit" = line.as_str() {
|
||||
break;
|
||||
// } else if let "trace" = line.as_str() {
|
||||
// node.trace_crdt();
|
||||
// continue;
|
||||
} else {
|
||||
let fake = utils::fake_transaction("foo123".to_string());
|
||||
// stdin_sender.send(fake).await.unwrap();
|
||||
fake
|
||||
};
|
||||
tracing::info!("sending {:?}", signed_op);
|
||||
let json = serde_json::to_string(&signed_op).unwrap();
|
||||
handle.text(json).unwrap();
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user