pub struct Context {
pub content: Arc<Mutex<ContentMap>>,
pub lookup_handler: LookupHandler<Id, ContentStatus, Error>,
pub loaded: AtomicUsize,
}Expand description
Registry and loading context for DOM content, tracking declared content entries, de-duplicating in-flight load requests and counting loaded items.
Fields§
§content: Arc<Mutex<ContentMap>>Map of registered content entries keyed by their id.
lookup_handler: LookupHandler<Id, ContentStatus, Error>Coordinates concurrent load requests so that each content id is only loaded once while other callers await the shared result.
loaded: AtomicUsizeRunning count of content entries that have been loaded.
Implementations§
Source§impl Context
impl Context
Sourcepub fn declare(&self, content: ContentList<'_>)
pub fn declare(&self, content: ContentList<'_>)
Register the given content entries with this context, making them available for later loading by id.
Sourcepub fn get(&self, id: &Id) -> Option<Arc<Content>>
pub fn get(&self, id: &Id) -> Option<Arc<Content>>
Return the registered Content entry for the given id, if any.
Sourcepub async fn load_content(
self: &Arc<Self>,
content: Arc<Content>,
) -> Result<ContentStatus>
pub async fn load_content( self: &Arc<Self>, content: Arc<Content>, ) -> Result<ContentStatus>
Load a single content entry, injecting it into the DOM. Concurrent
requests for the same content are de-duplicated via the lookup handler,
and already-loaded content resolves immediately as ContentStatus::Exists.