Guest User

Untitled

a guest
Jul 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. extern crate tokio;
  2.  
  3. use tokio::prelude::*;
  4.  
  5. fn files() -> impl Stream<Item = u32, Error = std::io::Error> {
  6. stream::iter_ok(vec![10, 20, 30])
  7. }
  8.  
  9. fn read_chunks(file: u32) -> impl Stream<Item = u32, Error = std::io::Error> {
  10. stream::iter_ok(vec![file + 1, file + 2, file + 3, file + 4, file + 5])
  11. }
  12. fn main() {
  13. let run = files()
  14. .map(move |fh| {
  15. println!("Streaming file {}", fh);
  16. read_chunks(fh)
  17. .map(move |ret| {
  18. println!("{}", ret);
  19. })
  20. .for_each(|_| Ok(()))
  21. })
  22. .buffer_unordered(2)
  23. .collect()
  24. .map(|_| ())
  25. .map_err(|_| ());
  26.  
  27. tokio::run(run);
  28. }
Add Comment
Please, Sign In to add comment