Skip to content

Commit

Permalink
counter demo works
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgb committed Aug 4, 2024
1 parent 2907a91 commit bf2ba47
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion aper-websocket-client/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
let pending = Arc::new(Mutex::new(None));
let pending_ = pending.clone();
let ws_ = ws.clone();
let conn_handler = Closure::<dyn FnMut(JsValue)>::wrap(Box::new(move |e: JsValue| {
let conn_handler = Closure::<dyn FnMut(JsValue)>::wrap(Box::new(move |_: JsValue| {
let mut pending = pending_.lock().unwrap();
if let Some(message) = pending.take() {
match message {
Expand Down
5 changes: 0 additions & 5 deletions aper/src/aper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,11 @@ impl<A: Aper> AperServer<A> {

pub fn apply(&mut self, intent: &A::Intent) -> Result<Vec<Mutation>, A::Error> {
let overlay = self.state.push_overlay();
println!("00 {:?}", overlay.collect());

let mut sm = A::attach(overlay.clone());

sm.apply(&intent)?;

println!("aa {:?}", overlay.collect());
overlay.dump();
overlay.dump();

self.version += 1;

let mutations = overlay.into_mutations();
Expand Down
3 changes: 0 additions & 3 deletions aper/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ impl<A: Aper> ServerHandle<A> {
let mut server_borrow = self.server.lock().unwrap();
let Ok(mutations) = server_borrow.apply(&intent) else {
// still need to ack the client.
println!("here11");

self.callbacks.get(&self.client_id).map(|callback| {
callback(&MessageToClient::Apply {
Expand All @@ -147,8 +146,6 @@ impl<A: Aper> ServerHandle<A> {
return;
};

println!("Mutations: {:?}", mutations);

let version = server_borrow.version();

let message_to_others = MessageToClient::Apply {
Expand Down
17 changes: 9 additions & 8 deletions aper/src/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,18 @@ impl TreeMapRef {
}

pub fn mutate(&self, mutations: &Vec<Mutation>) {
let mut reference = self.reference.lock().unwrap();

for mutation in mutations {
let mut map_lock = self.map.maps.lock().unwrap();
let mut map = map_lock
.entry(mutation.prefix.clone())
.or_insert_with(|| Arc::new(Mutex::new(BTreeMap::new())))
.lock()
.unwrap();

for (key, value) in &mutation.entries {
match value {
Some(value) => reference.insert(key.clone(), Some(value.clone())),
None => reference.insert(key.clone(), None),
Some(value) => map.insert(key.clone(), Some(value.clone())),
None => map.insert(key.clone(), None),
};
}
}
Expand Down Expand Up @@ -197,8 +202,4 @@ impl TreeMapRef {
pub fn collect(&self) -> BTreeMap<Vec<Bytes>, BTreeMap<Bytes, Bytes>> {
self.map.collect()
}

pub fn dump(&self) {
println!("overlay: {:?}", self.map.maps);
}
}
4 changes: 0 additions & 4 deletions examples/counter/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ impl Aper for Counter {
fn apply(&mut self, event: &CounterIntent) -> Result<(), ()> {
let value = self.value.get();

println!("Current value: {}", value);

match event {
CounterIntent::Add(i) => {
self.value.set(value + i);
Expand All @@ -40,8 +38,6 @@ impl Aper for Counter {
}
}

println!("New value: {}", self.value.get());

Ok(())
}
}

0 comments on commit bf2ba47

Please sign in to comment.