Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fixed_read(db, key) {
- var value = db.read(key);
- while (true) {
- // If we try to write the read value then we
- const written = db.updateWhen(key, {
- predicate: `x => x.ver==${value.ver}`,
- value: { ver: value.ver+1, val: value.val}
- });
- if (!written.isConflict) {
- // either succeed and return the just written value
- return written.value;
- }
- // or fail and use a newer value and repeat the trick.
- value = written.conflict;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement