Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. function fixed_read(db, key) {
  2. var value = db.read(key);
  3. while (true) {
  4. // If we try to write the read value then we
  5. const written = db.updateWhen(key, {
  6. predicate: `x => x.ver==${value.ver}`,
  7. value: { ver: value.ver+1, val: value.val}
  8. });
  9. if (!written.isConflict) {
  10. // either succeed and return the just written value
  11. return written.value;
  12. }
  13. // or fail and use a newer value and repeat the trick.
  14. value = written.conflict;
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement