Express filter as a future

This commit is contained in:
Tangent 128 2018-04-14 04:53:18 -04:00
parent 8b0467c1d7
commit 9123d63343

View file

@ -5,7 +5,7 @@ use std::{
}; };
use clap::{App, Arg, ArgMatches, SubCommand}; use clap::{App, Arg, ArgMatches, SubCommand};
use futures::Stream; use futures::prelude::*;
use super::StdinStream; use super::StdinStream;
use webmetro::{ use webmetro::{
@ -40,11 +40,8 @@ pub fn run(args: &ArgMatches) -> Result<(), Box<Error>> {
chunk_stream = Box::new(chunk_stream.throttle()); chunk_stream = Box::new(chunk_stream.throttle());
} }
let stdout = io::stdout(); let result = chunk_stream.fold((), |_, chunk| {
let mut stdout_writer = stdout.lock(); io::stdout().write_all(chunk.as_ref())
for chunk in chunk_stream.wait() { }).wait();
stdout_writer.write_all(chunk?.as_ref())?; result
}
Ok(())
} }