aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/document_file.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/document_file.rs')
-rw-r--r--src/swarm/document_file.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/swarm/document_file.rs b/src/swarm/document_file.rs
index e066e27..4c7843d 100644
--- a/src/swarm/document_file.rs
+++ b/src/swarm/document_file.rs
@@ -25,6 +25,20 @@ pub(crate) async fn run(state: AppState) {
}
}
+/// At a clean stop, after the last `flush`: the file marked as holding everything this
+/// node wrote (`DocumentFile::close`), where it does (ready, not rejoining, up to the
+/// document's heads), so a restart may write on as the same actor (`--keep-actor`).
+pub(crate) async fn close(state: &AppState) {
+ let Some(file) = state.document_file.clone() else {
+ return;
+ };
+ if state.remake.is_rejoining() || !state.is_ready().await {
+ return;
+ }
+ let heads = state.doc.read().await.doc.get_heads();
+ file.close(&heads);
+}
+
/// Writes what is due now (`DocumentFile::due`). Also called at shutdown.
pub(crate) async fn flush(state: &AppState) {
let Some(file) = state.document_file.clone() else {