Skip to content

Commit

Permalink
switch watcher to raw_watcher
Browse files Browse the repository at this point in the history
hopefully helps catch reload conditions more quickly, and notify
won't do any of its extra processing (that we ignore anyway)
  • Loading branch information
jebrosen committed Jul 4, 2018
1 parent ae855f1 commit 7b51fe6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions contrib/lib/src/templates/fairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,25 @@ mod context {
use std::ops::{Deref, DerefMut};
use std::sync::{RwLock, Mutex};
use std::sync::mpsc::{channel, Receiver};
use std::time::Duration;

use super::{Context, Engines};

use self::notify::{watcher, DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher};
use self::notify::{raw_watcher, RawEvent, RecommendedWatcher, RecursiveMode, Watcher};

/// Wraps a Context. With `cfg(debug_assertions)` active, this structure
/// additionally provides a method to reload the context at runtime.
pub struct ContextManager {
/// The current template context, inside an RwLock so it can be updated
context: RwLock<Context>,
/// A filesystem watcher and the receive queue for its events
watcher: Option<(RecommendedWatcher, Mutex<Receiver<DebouncedEvent>>)>,
watcher: Option<(RecommendedWatcher, Mutex<Receiver<RawEvent>>)>,
}

impl ContextManager {
pub fn new(ctxt: Context) -> ContextManager {
let (tx, rx) = channel();

let watcher = if let Ok(mut watcher) = watcher(tx, Duration::from_secs(1)) {
let watcher = if let Ok(mut watcher) = raw_watcher(tx) {
if watcher.watch(ctxt.root.clone(), RecursiveMode::Recursive).is_ok() {
Some((watcher, Mutex::new(rx)))
} else {
Expand Down

0 comments on commit 7b51fe6

Please sign in to comment.