mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-25 04:54:07 +00:00
Tinker with concurrency with FsSession
This commit is contained in:
parent
817ee31a23
commit
591b9c5f9a
2 changed files with 23 additions and 10 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::time::Instant;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use rand;
|
use rand;
|
||||||
|
|
||||||
|
|
@ -55,10 +56,22 @@ pub fn serve(project_path: &PathBuf, port: Option<u64>) {
|
||||||
|
|
||||||
println!("Using session config {:#?}", config);
|
println!("Using session config {:#?}", config);
|
||||||
|
|
||||||
let mut session = FsSession::new(&config);
|
let session = {
|
||||||
|
let mut session = FsSession::new(config.clone());
|
||||||
session.init();
|
session.init();
|
||||||
|
|
||||||
|
Arc::new(Mutex::new(session))
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: Let FsSession handle the main loop and spawn a bunch of threads
|
||||||
|
// ...since Rust stable doesn't have a channel select implementation
|
||||||
|
thread::spawn(move || {
|
||||||
loop {
|
loop {
|
||||||
session.step();
|
session.lock().unwrap().step();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
loop {
|
||||||
|
thread::park();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ pub enum FileItem {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FsSession<'a> {
|
pub struct FsSession {
|
||||||
pub config: &'a SessionConfig,
|
pub config: SessionConfig,
|
||||||
|
|
||||||
/// The in-memory files associated with each partition.
|
/// The in-memory files associated with each partition.
|
||||||
pub partition_files: HashMap<String, FileItem>,
|
pub partition_files: HashMap<String, FileItem>,
|
||||||
|
|
@ -36,10 +36,10 @@ pub struct FsSession<'a> {
|
||||||
watchers: HashMap<String, FileWatcher>,
|
watchers: HashMap<String, FileWatcher>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FsSession<'a> {
|
impl FsSession {
|
||||||
pub fn new(config: &SessionConfig) -> FsSession {
|
pub fn new(config: SessionConfig) -> FsSession {
|
||||||
FsSession {
|
FsSession {
|
||||||
config,
|
config: config,
|
||||||
partition_files: HashMap::new(),
|
partition_files: HashMap::new(),
|
||||||
watchers: HashMap::new(),
|
watchers: HashMap::new(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue