You need to call `rx.iter()` to iterate over events from a channel (#522)

This commit is contained in:
Michael Bryan 2018-01-03 19:32:49 +08:00 committed by GitHub
parent 6ba0162ff7
commit e74c376833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 6 deletions

View File

@ -3,6 +3,7 @@ extern crate clap;
extern crate chrono; extern crate chrono;
extern crate env_logger; extern crate env_logger;
extern crate error_chain; extern crate error_chain;
#[macro_use]
extern crate log; extern crate log;
extern crate mdbook; extern crate mdbook;
extern crate open; extern crate open;

View File

@ -52,7 +52,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
let address = format!("{}:{}", interface, port); let address = format!("{}:{}", interface, port);
let ws_address = format!("{}:{}", interface, ws_port); let ws_address = format!("{}:{}", interface, ws_port);
book.livereload = Some(format!( let livereload = Some(format!(
r#" r#"
<script type="text/javascript"> <script type="text/javascript">
var socket = new WebSocket("ws://{}:{}"); var socket = new WebSocket("ws://{}:{}");
@ -70,6 +70,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
"#, "#,
public_address, ws_port, RELOAD_COMMAND public_address, ws_port, RELOAD_COMMAND
)); ));
book.livereload = livereload.clone();
book.build()?; book.build()?;
@ -98,11 +99,26 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
#[cfg(feature = "watch")] #[cfg(feature = "watch")]
watch::trigger_on_change(&mut book, move |path, book_dir| { watch::trigger_on_change(&mut book, move |path, book_dir| {
println!("File changed: {:?}\nBuilding book...\n", path); println!("File changed: {:?}\nBuilding book...\n", path);
match MDBook::load(&book_dir).and_then(|mut b| b.build()) { // FIXME: This area is really ugly because we need to re-set livereload :(
Err(e) => println!("Error while building: {:?}", e),
_ => broadcaster.send(RELOAD_COMMAND).unwrap(), let livereload = livereload.clone();
let result = MDBook::load(&book_dir)
.map(move |mut b| {
b.livereload = livereload;
b
})
.and_then(|mut b| b.build());
if let Err(e) = result {
error!("Unable to load the book");
error!("Error: {}", e);
for cause in e.iter().skip(1) {
error!("\tCaused By: {}", cause);
}
} else {
let _ = broadcaster.send(RELOAD_COMMAND);
} }
println!("");
}); });
Ok(()) Ok(())

View File

@ -74,7 +74,7 @@ where
println!("\nListening for changes...\n"); println!("\nListening for changes...\n");
for event in rx.recv() { for event in rx.iter() {
match event { match event {
Create(path) | Write(path) | Remove(path) | Rename(_, path) => { Create(path) | Write(path) | Remove(path) | Rename(_, path) => {
closure(&path, &book.root); closure(&path, &book.root);