From 5f2fdae1ea54b73eeb2352a28c6558b1e344e4e2 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 1 Nov 2026 13:37:04 +0100 Subject: remake: copy stale view when writes stop This ensures that stale reads show every write that was answered. --- src/state/host.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/state/host.rs') diff --git a/src/state/host.rs b/src/state/host.rs index 7c3e165..30ebcdb 100644 --- a/src/state/host.rs +++ b/src/state/host.rs @@ -226,6 +226,19 @@ impl Host for AppState { async move { state.mutate_doc(f).await } } + fn refuse_writes(&self, copy: bool) -> impl Future> + Send { + let state = self.clone(); + async move { + tokio::task::spawn_blocking(move || { + let mut replica = state.doc.blocking_write(); + replica.writable = false; + copy.then(|| replica.doc.clone()) + }) + .await + .expect("document write task panicked") + } + } + fn accept_writes(&self) -> impl Future + Send { let state = self.clone(); async move { -- cgit v1.3.1