Skip to main content

Mountain/RPC/EchoAction/
ExtensionHostRegistry.rs

1
2//! Tracks which extension host owns which extension id. Populated from
3//! `$deltaExtensions` + `InitExtensionHost` payloads; read by
4//! `ExtensionRouter` when a request needs to be routed to a specific host.
5
6use std::{collections::HashMap, sync::Arc};
7
8use tokio::sync::RwLock;
9
10pub struct Struct {
11	Hosts:Arc<RwLock<HashMap<String, String>>>,
12}
13
14impl Struct {
15	pub fn new() -> Self { Self { Hosts:Arc::new(RwLock::new(HashMap::new())) } }
16
17	pub async fn Record(&self, ExtensionIdentifier:String, HostIdentifier:String) {
18		self.Hosts.write().await.insert(ExtensionIdentifier, HostIdentifier);
19	}
20
21	pub async fn Forget(&self, ExtensionIdentifier:&str) { self.Hosts.write().await.remove(ExtensionIdentifier); }
22
23	pub async fn Resolve(&self, ExtensionIdentifier:&str) -> Option<String> {
24		self.Hosts.read().await.get(ExtensionIdentifier).cloned()
25	}
26
27	pub async fn Count(&self) -> usize { self.Hosts.read().await.len() }
28}
29
30impl Default for Struct {
31	fn default() -> Self { Self::new() }
32}