Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created July 2, 2018 03:39
Show Gist options
  • Save rust-play/b9ed951ee0064c7ff76d1be859bea1fd to your computer and use it in GitHub Desktop.
Save rust-play/b9ed951ee0064c7ff76d1be859bea1fd to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
let pipeline = framed_reader
.map(move |b| {
let message: proto::Message = bincode::deserialize(&b).unwrap();
let file;
match message {
proto::Message::Request(m) => {
file = m.file.clone();
if m.file == Path::new("/root/test/file").to_path_buf() {
let pool = ThreadPool::new();
pool.spawn(lazy(move || {
poll_fn(move || {
blocking(|| {
println!("Waiting");
let duration = time::Duration::from_millis(10000);
let now = time::Instant::now();
thread::sleep(duration);
}).map_err(|_| panic!("the threadpool shut down"))
})
}));
pool.shutdown_on_idle().wait().unwrap();
}
files.insert(m.id, m.file);
}
_ => {
panic!("Oh deary me, we aren't in sync: diff");
}
};
File::open(file)
.and_then(|file| io::read_to_end(file, vec![]))
.map(|res| {
let (meta, buf) = res;
println!("{:#?}", meta);
BytesMut::from(buf)
})
})
.buffer_unordered(100)
.forward(framed_writer)
.map(|_| {})
.map_err(|err| {
println!("frame error = {:?}", err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment