- Inside the bin folder, create a new file called combinators.rs.
- Add the following code and run it with cargo run --bin combinators:
1 extern crate futures; 2 extern crate futures_util; 3 4 use futures::prelude::*; 5 use futures::channel::{mpsc, oneshot}; 6 use futures::executor::block_on; 7 use futures::future::{ok, err, join_all, select_all, poll_fn}; 8 use futures::stream::iter_result; 9 use futures_util::stream::select_all as select_all_stream; 10 11 use std::thread; 12 13 const FINISHED: Result<Async<()>, Never> = Ok(Async::Ready(()));
- Let's add our join_all example function:
15 fn join_all_example() { 16 let future1 = Ok::<_, ()>(vec![1, 2, 3]); 17 let future2 = Ok(vec![10, 20, 30]); 18 let future3 = Ok(vec![100, 200, 300]); 19 20 let results = block_on(join_all(vec![future1, future2,
future3])).unwrap(); 21 println!("Results of joining 3 futures: {:?}"...