aboutsummaryrefslogtreecommitdiffstats
path: root/src/state/host.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/host.rs')
-rw-r--r--src/state/host.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/state/host.rs b/src/state/host.rs
index 24a989e..6bb9d3b 100644
--- a/src/state/host.rs
+++ b/src/state/host.rs
@@ -12,7 +12,7 @@ use tracing::debug;
use super::{AppState, HelloState, NodeLifecycle, StaleView, Standing};
use crate::document::replica::Epoch;
-use crate::document::store::ChangeSet;
+use crate::document::store::{ChangeSet, StoreError};
use crate::document::{ChangeHash, Document, ReadDoc, Transaction};
use crate::remake::{Host, PeerSummary, RemakeState};
@@ -220,12 +220,22 @@ impl Host for AppState {
where
F: FnOnce(&mut Transaction<'_>) -> Result<T, E> + Send + 'static,
T: Send + 'static,
- E: Send + 'static,
+ E: From<StoreError> + Send + 'static,
{
let state = self.clone();
async move { state.mutate_doc(f).await }
}
+ fn accept_writes(&self) -> impl Future<Output = ()> + Send {
+ let state = self.clone();
+ async move {
+ // On the blocking pool, as every write lock is taken.
+ tokio::task::spawn_blocking(move || state.doc.blocking_write().writable = true)
+ .await
+ .expect("document write task panicked");
+ }
+ }
+
fn apply_change(
&self,
change: crate::document::Change,
@@ -255,6 +265,7 @@ impl Host for AppState {
fn switch_epoch<E, F>(
&self,
epoch: Epoch,
+ writable: bool,
f: F,
) -> impl Future<Output = Result<Document, E>> + Send
where
@@ -271,6 +282,7 @@ impl Host for AppState {
let old_doc = std::mem::replace(&mut replica.doc, new_doc);
replica.epoch = epoch;
replica.epoch_seq += 1;
+ replica.writable = writable;
replica.refresh_heads();
// Updated under the same lock, so the cached epoch never disagrees
// with the document for anyone holding the lock.