do a read on each add
This commit is contained in:
parent
4c89bf7a5c
commit
7a0147f88e
1 changed files with 3 additions and 5 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue