mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-24 06:34:09 +00:00
Tidy up and reorganize things, they're just about in shape
This commit is contained in:
parent
d9aec292fa
commit
5a82879115
9 changed files with 174 additions and 191 deletions
44
server/src/partition_watcher.rs
Normal file
44
server/src/partition_watcher.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
use std::time::Duration;
|
||||
use std::thread;
|
||||
|
||||
use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher, watcher};
|
||||
|
||||
use partition::Partition;
|
||||
|
||||
pub struct PartitionWatcher {
|
||||
pub watcher: RecommendedWatcher,
|
||||
pub partition: Partition,
|
||||
}
|
||||
|
||||
impl PartitionWatcher {
|
||||
pub fn start_new(partition: Partition, tx: Sender<(String, DebouncedEvent)>) -> PartitionWatcher {
|
||||
let (watch_tx, watch_rx) = channel();
|
||||
|
||||
let mut watcher = watcher(watch_tx, Duration::from_millis(100)).unwrap();
|
||||
|
||||
watcher.watch(&partition.path, RecursiveMode::Recursive).unwrap();
|
||||
|
||||
let partition_name = partition.name.clone();
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
match watch_rx.recv() {
|
||||
// TODO: Transform DebouncedEvent to some sort of FileChange object
|
||||
Ok(event) => match tx.send((partition_name.clone(), event)) {
|
||||
Ok(_) => {},
|
||||
Err(_) => break,
|
||||
},
|
||||
Err(_) => break,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
PartitionWatcher {
|
||||
partition,
|
||||
watcher,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(self) {
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue