Consuming SignedOp when it's handled

This commit is contained in:
Dave Hrycyszyn
2024-06-11 18:42:13 +01:00
parent 546a45bb3a
commit 097fbea9a0
2 changed files with 8 additions and 3 deletions

View File

@@ -46,7 +46,7 @@ impl SideNode {
}
match self.incoming_receiver.try_recv() {
Ok(incoming) => {
self.handle_incoming(&incoming);
self.handle_incoming(incoming);
}
Err(_) => {} // ignore empty channel errors in this PoC
}
@@ -59,9 +59,9 @@ impl SideNode {
self.handle.call(to_send).unwrap();
}
fn handle_incoming(&mut self, incoming: &SignedOp) {
fn handle_incoming(&mut self, incoming: SignedOp) {
println!("WINNNINGINGINGINGINGIGNIGN");
self.crdt.apply(incoming.clone());
self.crdt.apply(incoming);
}
pub(crate) fn add_transaction_local(

View File

@@ -37,6 +37,8 @@ impl ezsockets::ClientExt for WebSocketClient {
// match on it.
type Call = String;
/// When we receive a text message, apply the crdt operation contained in it to our
/// local crdt.
async fn on_text(&mut self, text: String) -> Result<(), ezsockets::Error> {
tracing::info!("received text: {text:?}");
let incoming: bft_json_crdt::json_crdt::SignedOp = serde_json::from_str(&text).unwrap();
@@ -44,11 +46,14 @@ impl ezsockets::ClientExt for WebSocketClient {
Ok(())
}
/// When we receive a binary message, log the bytes. Currently unused.
async fn on_binary(&mut self, bytes: Vec<u8>) -> Result<(), ezsockets::Error> {
tracing::info!("received bytes: {bytes:?}");
Ok(())
}
/// Call this with the `Call` type to send application data to the websocket client
/// (and from there, to the server).
async fn on_call(&mut self, call: Self::Call) -> Result<(), ezsockets::Error> {
tracing::info!("sending signed op: {call:?}");
self.handle.text(call)?;