Skip to content

Instantly share code, notes, and snippets.

@jorendorff
Last active November 2, 2019 16:47
Show Gist options
  • Save jorendorff/5ed7f21a043d6cfa4cfa5897ed635cb0 to your computer and use it in GitHub Desktop.
Save jorendorff/5ed7f21a043d6cfa4cfa5897ed635cb0 to your computer and use it in GitHub Desktop.
if input.is_some() {
let tx = tx.clone();
let mut input = BufReader::new(input.unwrap());
::std::thread::spawn(
move || {
let mut buf = String::new();
// TODO read_until pegs CPU at 100% without a sleep there
while let Ok(len) = ::std::io::BufRead::read_line(&mut input, &mut buf) {
if len == 0 {
break;
}
let _ = tx.send(RagerEvent::Line(buf.as_bytes().to_owned()));
buf.clear();
}
let _ = tx.send(RagerEvent::EndInput);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment