Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operation ordering guarantee #799

Closed
ronag opened this issue Feb 5, 2022 · 2 comments
Closed

Operation ordering guarantee #799

ronag opened this issue Feb 5, 2022 · 2 comments
Labels
question Support or open question(s)

Comments

@ronag
Copy link

ronag commented Feb 5, 2022

Haven't been able to find a definitive answer on this. Does level down guarantee that writes are always visible for reads, in order.

e.g. is the following code guaranteed to always work?

db.put(key, val, (err) => { 
  /* assume no err */ 
})
db.get(key, (err, val2) => {
  /* assume no err */
  assert.strictEqual(val, val2)
})

Or do I need to do something like:

const pending = new Map()
pending.set(key, val)
db.put(key, val, (err) => { 
  /* assume no err */ 
  pending.delete(key)
})
db.get(key, (err, val2) => {
  /* assume no err */
  val2 = pending.get(key) ?? val2
  assert.strictEqual(val, val2)
})
@vweevers vweevers added the question Support or open question(s) label Feb 5, 2022
@vweevers
Copy link
Member

vweevers commented Feb 5, 2022

e.g. is the following code guaranteed to always work?

No, because each operation (put, get, del, etc) starts an async worker that is independent of the others. We make no guarantee about the order of these.

Node.js might but if it does that should be considered a side-effect rather than by design.

@ronag ronag closed this as completed Feb 5, 2022
@ronag
Copy link
Author

ronag commented Feb 5, 2022

Thanks for the answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Support or open question(s)
Projects
None yet
Development

No branches or pull requests

2 participants