pub struct AppContext {
pub db_context: DbContext,
pub event_hub: Arc<EventHub>,
pub shutdown_rx: Receiver<()>,
pub undo_redo_manager: Arc<Mutex<UndoRedoManager>>,
pub long_operation_manager: Arc<Mutex<LongOperationManager>>,
/* private fields */
}Expand description
Application context that holds all shared state.
Shutdown lifecycle: when AppContext::shutdown is called the shared
shutdown_tx is dropped, which makes every cloned shutdown_rx
(held by EventHubClient::start threads) see Disconnected on its
next recv() and exit. No polling and no atomic flag needed.
Fields§
§db_context: DbContext§event_hub: Arc<EventHub>§shutdown_rx: Receiver<()>Receiver clones are handed to background event-hub threads.
Threads exit when the matching sender is dropped via
AppContext::shutdown.
undo_redo_manager: Arc<Mutex<UndoRedoManager>>§long_operation_manager: Arc<Mutex<LongOperationManager>>Implementations§
Source§impl AppContext
impl AppContext
pub fn new() -> Self
Sourcepub fn new_sharing(other: &AppContext) -> Self
pub fn new_sharing(other: &AppContext) -> Self
A context that shares another’s event hub, shutdown channel and long-operation manager, with a private store and undo stack.
What may be shared and what may not is decided by undo. Every
repository’s snapshot/restore takes and puts back the whole store
(see Transaction::snapshot_store), so two documents in one store would
undo and roll each other back. The store and the undo manager therefore
stay private to each document.
The event hub can be shared, and that is where the cost is: draining one costs an OS thread, so a hub per document is a thread per document. A stream over a book-length manuscript opens more than a hundred.
Because the hub is shared, so is the shutdown channel: a document that stopped the pump on its own way out would stop it for every sibling. The owner of the shared context is what decides when the pump ends.
Trait Implementations§
Source§impl Clone for AppContext
impl Clone for AppContext
Source§fn clone(&self) -> AppContext
fn clone(&self) -> AppContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more