Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use futures::{
- future,
- stream::{self, Stream},
- }; // 0.1.25;
- use tokio; // 0.1.14
- fn main() {
- let stream = stream::iter_ok({
- (0..10).map(|num| {
- println!("Started {}", num);
- match num % 3 {
- 0 => future::ok(num),
- _ => future::err(num),
- }
- })
- })
- .buffer_unordered(2);
- let stream = stream
- .inspect_err(|err| println!("Error on {:?}", err))
- .then(|r| future::ok(stream::iter_ok::<_, ()>(r)))
- .flatten()
- .for_each(|n| {
- println!("Success on {:?}", n);
- Ok(())
- });
- tokio::run({
- stream
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement