-
-
Save habnabit/e7efb5cf104303a90de6565dc0e69e7a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains 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 | |
.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