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" => {
|
"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()
|
||||||
|
|
Loading…
Reference in a new issue