<commit_before>use middleware::HandlebarsEngine;

use notify::{RecommendedWatcher, Error, Watcher};
use std::path::Path;
use std::sync::mpsc::channel;
use std::sync::Arc;
use std::thread;

fn _watch (p: &Path) -> Result<(), Error>{
    let (tx, rx) = channel();
    let mut watcher: RecommendedWatcher = try!(Watcher::new(tx));
    try!(watcher.watch(p));
    let _ = rx.recv();
    Ok(())
}

pub trait Watchable {
    fn watch(&self);
}

impl Watchable for Arc<HandlebarsEngine> {
    #[allow(while_true)]
    fn watch (&self) {
        let hbs = self.clone();
        thread::spawn(move || {
            println!("watching path: {}", hbs.prefix);
            let prefix = hbs.prefix.clone();
            let path = Path::new(&prefix);
            while true {
                match _watch(&path) {
                    Ok(_) => {
                        println!("things changed");
                        hbs.reload();
                    },
                    Err(e) => {
                        println!("Failed to watch directory: {:?}", e);
                        panic!();
                    }
                }
            }
        });
    }
}<commit_msg>(fix) while true -> loop<commit_after>use middleware::HandlebarsEngine;

use notify::{RecommendedWatcher, Error, Watcher};
use std::path::Path;
use std::sync::mpsc::channel;
use std::sync::Arc;
use std::thread;

fn _watch (p: &Path) -> Result<(), Error>{
    let (tx, rx) = channel();
    let mut watcher: RecommendedWatcher = try!(Watcher::new(tx));
    try!(watcher.watch(p));
    let _ = rx.recv();
    Ok(())
}

pub trait Watchable {
    fn watch(&self);
}

impl Watchable for Arc<HandlebarsEngine> {
    fn watch (&self) {
        let hbs = self.clone();
        thread::spawn(move || {
            println!("watching path: {}", hbs.prefix);
            let prefix = hbs.prefix.clone();
            let path = Path::new(&prefix);
            loop {
                match _watch(&path) {
                    Ok(_) => {
                        println!("things changed");
                        hbs.reload();
                    },
                    Err(e) => {
                        println!("Failed to watch directory: {:?}", e);
                        panic!();
                    }
                }
            }
        });
    }
}
{'fraction_non_alphanumeric': 0.15773552290406223, 'fraction_numerical': 0.0, 'mean_word_length': 1.6128668171557563, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '51065', 'n_tokens_mistral': 682, 'n_tokens_neox': 657, 'n_words': 149}