mirror of
https://github.com/hexedtech/codemp.git
synced 2024-12-23 13:24:54 +01:00
feat: jank workspace event poll/get
This commit is contained in:
parent
f2be80427a
commit
f699d2e8fe
1 changed files with 14 additions and 0 deletions
|
@ -39,6 +39,7 @@ struct WorkspaceInner {
|
|||
user_id: Uuid, // reference to global user id
|
||||
cursor: cursor::Controller,
|
||||
buffers: DashMap<String, buffer::Controller>,
|
||||
event: InternallyMutable<WorkspaceEventInner>,
|
||||
filetree: DashSet<String>,
|
||||
users: DashMap<Uuid, User>,
|
||||
services: Services
|
||||
|
@ -76,6 +77,7 @@ impl Workspace {
|
|||
id,
|
||||
user_id,
|
||||
cursor: controller,
|
||||
event: InternallyMutable::new(WorkspaceEventInner::Join(UserJoin { user: Identity { id: user_id.to_string() } })),
|
||||
buffers: DashMap::default(),
|
||||
filetree: DashSet::default(),
|
||||
users: DashMap::default(),
|
||||
|
@ -101,6 +103,7 @@ impl Workspace {
|
|||
tracing::warn!("workspace {} received empty event", name)
|
||||
}
|
||||
Ok(Some(WorkspaceEvent { event: Some(ev) })) => {
|
||||
let _ev = ev.clone();
|
||||
match ev {
|
||||
WorkspaceEventInner::Join(UserJoin { user }) => {
|
||||
inner.users.insert(user.clone().into(), User { id: user.into() });
|
||||
|
@ -122,6 +125,7 @@ impl Workspace {
|
|||
}
|
||||
}
|
||||
}
|
||||
inner.event.set(_ev);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -204,6 +208,16 @@ impl Workspace {
|
|||
}
|
||||
}
|
||||
|
||||
/// await and return next workspace event
|
||||
///
|
||||
/// TODO dont use inner proto type
|
||||
/// TODO can it fail? are we just masking?
|
||||
/// TODO tiemout i guess
|
||||
pub async fn poll(&self) -> WorkspaceEventInner {
|
||||
self.0.event.wait().await;
|
||||
self.0.event.get()
|
||||
}
|
||||
|
||||
/// fetch a list of all buffers in a workspace
|
||||
pub async fn fetch_buffers(&self) -> crate::Result<()> {
|
||||
let mut workspace_client = self.0.services.ws();
|
||||
|
|
Loading…
Reference in a new issue