mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-03 00:14:21 +01:00
Completions can now carry errors inside of them. This allows us to wait for a completion to complete or to error. When it errors we can properly tell the caller of `wait_for_completion` that we errored. This will also allow us to abort completions. Currently, this just creates the scaffold for us to store the error in the completion. But to correctly achieve this, it will require some refactor of our IO implementations to store the `run_once` error for a particular completion inside of it instead of short circuiting. This would also allow us to check for an error in `program.step` and properly rollback. Also, creates default impls for some common IO methods, this is important specially for `wait_for_completion` as we want to check the error in the `Completion` before returning `Ok`. Maybe we could also accept a Result type in the completion callback so that we can execute some sort of compensating action on error, like unlocking a page so it can be evicted by the page cache later. **EDIT:** actually implemented this in this PR. We store a `Result` object inside `CompletionInner` behind a `OnceLock` for thread-safety. We also pass a result object to Completion callbacks to execute compensating actions. Reviewed-by: Avinash Sajjanshetty (@avinassh) Closes #2589