Wrap RojoTree in Mutex

This commit is contained in:
Lucien Greathouse
2019-09-13 12:57:37 -07:00
parent 7a7e9087e6
commit 1d84d3e440
2 changed files with 10 additions and 7 deletions

View File

@@ -1,4 +1,7 @@
use std::collections::HashSet;
use std::{
collections::HashSet,
sync::{Mutex, MutexGuard},
};
use crate::{
imfs::new::{Imfs, ImfsFetcher},
@@ -12,7 +15,7 @@ use crate::{
pub struct ServeSession<F> {
root_project: Option<Project>,
session_id: SessionId,
tree: RojoTree,
tree: Mutex<RojoTree>,
message_queue: MessageQueue<()>, // TODO: Real message type
imfs: Imfs<F>,
}
@@ -25,14 +28,14 @@ impl<F: ImfsFetcher> ServeSession<F> {
ServeSession {
session_id,
root_project,
tree,
tree: Mutex::new(tree),
message_queue,
imfs,
}
}
pub fn tree(&self) -> &RojoTree {
&self.tree
pub fn tree(&self) -> MutexGuard<'_, RojoTree> {
self.tree.lock().unwrap()
}
pub fn imfs(&self) -> &Imfs<F> {

View File

@@ -13,8 +13,8 @@ use crate::{
serve_session::ServeSession,
web::{
interface::{
Instance, NotFoundError, ReadResponse, ServerInfoResponse, SubscribeResponse,
PROTOCOL_VERSION, SERVER_VERSION,
Instance, NotFoundError, ReadResponse, ServerInfoResponse, PROTOCOL_VERSION,
SERVER_VERSION,
},
util::{json, json_ok},
},