do a read on each add

This commit is contained in:
Joe Ardent 2024-06-04 13:04:55 -07:00
parent 4c89bf7a5c
commit 7a0147f88e

View file

@ -36,13 +36,11 @@ impl Node for Counter {
"add" => { "add" => {
let delta = req.body.payload.get("delta").unwrap().as_i64().unwrap(); let delta = req.body.payload.get("delta").unwrap().as_i64().unwrap();
loop { loop {
let cur = self.0; let cur = kv.read(runner, KEY).unwrap().unwrap().as_i64().unwrap();
let cur = cur.max(self.0);
let new = cur + delta; let new = cur + delta;
match kv.cas(runner, KEY, cur.into(), new.into(), false) { match kv.cas(runner, KEY, cur.into(), new.into(), false) {
Err(_e) => { Err(_e) => {}
let cur = kv.read(runner, KEY).unwrap().unwrap().as_i64().unwrap();
self.0 = cur;
}
Ok(_) => { Ok(_) => {
let nodes = runner let nodes = runner
.nodes() .nodes()