USER CACHE
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user