Skip to main content

AppContext

Struct AppContext 

Source
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

Source

pub fn new() -> Self

Source

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.

Source

pub fn shutdown(&self)

Signal background event-hub threads to stop. Idempotent: the second call is a no-op because the sender has already been taken.

Trait Implementations§

Source§

impl Clone for AppContext

Source§

fn clone(&self) -> AppContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AppContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AppContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.