-
-
Save tobz/ccd8f3af6c91f1e6f96f64847f0a023e to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let pipeline = framed_reader | |
26 .map(move |b| { | |
25 let message: proto::Message = bincode::deserialize(&b).unwrap(); | |
24 let file; | |
23 match message { | |
22 proto::Message::Request(m) => { | |
21 file = m.file.clone(); | |
20 } | |
19 _ => { | |
18 panic!("Message incorrect") | |
17 } | |
16 }; | |
15 let mut buffer = Vec::new(); | |
14 File::open(file.clone()) | |
13 .map(|mut file| { | |
12 AsyncRead::read_buf(&mut file, &mut buffer).unwrap(); | |
11 buffer | |
10 }) | |
9 .and_then(move |buf| { | |
8 poll_fn(move || { | |
7 let buf = buf.clone(); | |
6 let file = file.clone(); | |
5 | |
4 println!("Sending file {:?}", file); | |
3 blocking(move || { | |
2 if file == Path::new("/root/test/file").to_path_buf() { | |
1 println!("Waiting"); | |
79 thread::sleep(time::Duration::from_millis(10000)); | |
1 } | |
2 buf | |
3 }).map_err(|_| panic!("the threadpool shut down")) | |
4 }) | |
5 }) | |
6 }) | |
7 .buffer_unordered(100) | |
8 .forward(framed_writer) | |
9 .map(|_| ()) | |
10 .map_err(|err: std::io::Error| { | |
11 println!("frame error = {:?}", err); | |
12 }); | |
13 | |
14 tokio::spawn(pipeline); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment