Rust futures
join_all
has changed behaviour.
When you had a bunch of futures that you want to wait to complete, you could
join them with
futures::future::join_all
and wait on the joined future created.
Futures had an implicit result with the Item
& Error
type parameters on the
Future
trait, so all futures "could fail".
join_all
would return a single Error
if one future fails and not wait
for all the futures to complete.
This is inconvenient if you don't want everything to fail because one of the futures failed. E.g. if you send off a bunch of requests, not minding if some of them fail, but wanting to get the data from the successful ones.
This could be worked around by packing the result of each future into an Ok
variant of the Result
enum, so as far as join_all
is concerned, every
future has succeeded, and unwrap
'ing those results after joining.
Here's an example of
this
using futures:0.1
.
Now futures don't have this implicit result, and the Future
trait has a
single type parameter: Output
. Futures don't need to "be able to fail" now.
When futures can fail, they return Result
as their Output
type.
futures::future::join_all
with now wait for all of the futures to complete, and when await
'd will
produce a collection of the Output
type of the futures. This makes the above
workaround unnecessary. The collection of futures can also be collected into a
Stream
. Here's an example of both these
approaches
using futures:0.3
.
The behaviour of bailing out once one future has failed and returning a single
error is now performed by
futures::future::try_join_all
.
try_join_all
behaves like old join_all
!