Function futures::future::join_all [−][src]
pub fn join_all<I>(i: I) -> JoinAll<I> where
I: IntoIterator,
I::Item: IntoFuture,
Expand description
Creates a future which represents a collection of the results of the futures given.
The returned future will drive execution for all of its underlying futures,
collecting the results into a destination Vec<T>
in the same order as they
were provided. If any future returns an error then all other futures will be
canceled and an error will be returned immediately. If all futures complete
successfully, however, then the returned future will succeed with a Vec
of
all the successful results.
Examples
use futures::future::*; let f = join_all(vec![ ok::<u32, u32>(1), ok::<u32, u32>(2), ok::<u32, u32>(3), ]); let f = f.map(|x| { assert_eq!(x, [1, 2, 3]); }); let f = join_all(vec![ Box::new(ok::<u32, u32>(1)), Box::new(err::<u32, u32>(2)), Box::new(ok::<u32, u32>(3)), ]); let f = f.then(|x| { assert_eq!(x, Err(2)); x });