USER CACHE

This commit is contained in:
2026-03-15 19:34:55 -04:00
parent 54eb7d4261
commit a32f6392b7
8 changed files with 84 additions and 51 deletions
+19 -3
View File
@@ -1,8 +1,16 @@
use std::sync::{Arc, Mutex, MutexGuard};
use openworm::net::UserId;
use crate::{net::NetHandle, ui::UserCache};
pub struct Session {
// TODO: this really should not be async...
// I mean it could be used async but all widgets
// are sync so I don't really think it makes sense to be...
#[derive(Clone)]
pub struct Session(Arc<Mutex<SessionInner>>);
pub struct SessionInner {
pub con: NetHandle,
pub user_id: UserId,
pub cache: UserCache,
@@ -10,10 +18,18 @@ pub struct Session {
impl Session {
pub fn new(con: NetHandle, user_id: UserId) -> Self {
Self {
Self(Arc::new(Mutex::new(SessionInner {
cache: UserCache::new(con.clone()),
con,
user_id,
}
})))
}
pub fn con(&self) -> NetHandle {
self.get().con.clone()
}
pub fn get(&self) -> MutexGuard<'_, SessionInner> {
self.0.try_lock().unwrap()
}
}