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" => {
let delta = req.body.payload.get("delta").unwrap().as_i64().unwrap();
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;
match kv.cas(runner, KEY, cur.into(), new.into(), false) {
Err(_e) => {
let cur = kv.read(runner, KEY).unwrap().unwrap().as_i64().unwrap();
self.0 = cur;
}
Err(_e) => {}
Ok(_) => {
let nodes = runner
.nodes()