Expand description
DocumentActor – the tokio task that owns one document’s
writable state (DESIGN.md §5.7, §5.6.8).
§Responsibilities
- Exclusive ownership of one [
lattice_core::Document]. No other code path holds a&mut Document; mutations arrive asActorMsgvariants on the bounded mailbox. - Snapshot publish after every committed mutation. The
actor builds a
DocumentSnapshotfrom the post-commit state and writes it to thePublishedSnapshotcell withstore_releasesemantics. - Unbounded mailbox – audit slice 6 / H3. The mailbox
was originally bounded with a
try_send->Busypath for callers; in practice, App-sideapply_edit_blockingdiscardedBusysilently and bursts could desync the buffer from what the user typed. Unbounded eliminates the silent-drop class entirely; queue depth bounds itself by edit rate × actor-stall-duration (typing is human-paced). - Graceful shutdown – when every
crate::RopeDocumentHandleis dropped the mailbox closes; the actor’srecvloop exits naturally.
§Why one task per document, not a thread
Documents are I/O-bound (file save/open, future LSP
attribution); a tokio task is the right granularity. The
LocalSet complexity of “stay on one thread” isn’t needed
because Document is Send. Across cores the actor still has
exclusive logical ownership – only one task handles any given
document.
§Why the actor builds the snapshot, not the handle
Snapshot publish happens inside the actor’s task, after the mutation. Doing it on the handle side would race with concurrent readers and miss the publish-before-respond ordering required by the §5.6.8 acquire/release contract.
Structs§
- Applied
Edit - What an
apply_editproduced. The caller uses this to log change events and to construct an inverseEditfor the undo stack. - Document
Actor - The actor task. Constructed by
crate::spawn_document.