SHARE
TWEET

Untitled

a guest Mar 25th, 2019 37 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use futures::{
  2.     future,
  3.     stream::{self, Stream},
  4. }; // 0.1.25;
  5. use tokio; // 0.1.14
  6.  
  7. fn main() {
  8.     let stream = stream::iter_ok({
  9.         (0..10).map(|num| {
  10.             println!("Started {}", num);
  11.             match num % 3 {
  12.                 0 => future::ok(num),
  13.                 _ => future::err(num),
  14.             }
  15.         })
  16.     })
  17.     .buffer_unordered(2);
  18.  
  19.     let stream = stream
  20.         .inspect_err(|err| println!("Error on {:?}", err))
  21.         .then(|r| future::ok(stream::iter_ok::<_, ()>(r)))
  22.         .flatten()
  23.         .for_each(|n| {
  24.             println!("Success on {:?}", n);
  25.             Ok(())
  26.         });
  27.  
  28.     tokio::run({
  29.         stream
  30.     });
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top