Skip to content

Instantly share code, notes, and snippets.

@habnabit
Forked from rust-play/playground.rs
Created July 2, 2018 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save habnabit/e7efb5cf104303a90de6565dc0e69e7a to your computer and use it in GitHub Desktop.
Save habnabit/e7efb5cf104303a90de6565dc0e69e7a 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;
let blocking_future;
match message {
proto::Message::Request(m) => {
file = m.file.clone();
if m.file == Path::new("/root/test/file").to_path_buf() {
blocking_future = 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"))
});
}
files.insert(m.id, m.file);
}
_ => {
panic!("Oh deary me, we aren't in sync: diff");
}
};
blocking_future
.and_then(move |()| 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