Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate tokio;
- use tokio::prelude::*;
- fn files() -> impl Stream<Item = u32, Error = std::io::Error> {
- stream::iter_ok(vec![10, 20, 30])
- }
- fn read_chunks(file: u32) -> impl Stream<Item = u32, Error = std::io::Error> {
- stream::iter_ok(vec![file + 1, file + 2, file + 3, file + 4, file + 5])
- }
- fn main() {
- let run = files()
- .map(move |fh| {
- println!("Streaming file {}", fh);
- read_chunks(fh)
- .map(move |ret| {
- println!("{}", ret);
- })
- .for_each(|_| Ok(()))
- })
- .buffer_unordered(2)
- .collect()
- .map(|_| ())
- .map_err(|_| ());
- tokio::run(run);
- }
Add Comment
Please, Sign In to add comment