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 env_logger;
extern crate error_chain;
#[macro_use]
extern crate log;
extern crate mdbook;
extern crate open;

View File

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

View File

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