mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-25 20:14:21 +01:00
This PR rewrites `turso-sync` package introduced in the #2334 and renames it to the `turso-sync-engine` (anyway the diff will be unreadable). The purpose of rewrite is to get rid of Tokio because this makes things harder when we wants to export bindings to WASM. In order to achieve "runtime"-agnostic sync core but still be able to use async/await machiner - this PR introduce usage of `genawaiter` crate which allows to transfer async/await Rust state machines to the generators. So, sync operations are just generators which can yield `IO` command in case where there is a need for it. Also, this PR introduces separate `ProtocolIo` in the `turso-sync- engine` which defines extra IO methods: 1. HTTP interaction 2. Atomic read/writes to the file. This is not strictly necessary and `turso_core::IO` methods can be extended to support few more things (like `delete`/`rename`) - but I decided that it will be simpler to just expose 2 more methods for sync protocol for the sake of atomic metadata update (which is very small - dozens of bytes). * As a bonus, we can store metadata for browser in the `LocalStorage` which may be more natural thing to do(?) (user can reset everything by just clearing local storage) The `ProtocolIo` works similarly to the `IO` in a sense that it gives the caller `Completion` which it can check periodically for new data. Closes #2457