I have a set of futures that I want to combine into one future that forces them to be executed sequentially.
I looked at the function futures_ordered
. It seems that the results are being returned sequentially, but futures are executed simultaneously.
I tried fold
futures by combining them with and_then
. However, this is difficult with the type system.
let tasks = vec![ok(()), ok(()), ok(())];
let combined_task = tasks.into_iter().fold(
ok(()),
|acc, task| acc.and_then(|_| task),
);
playground
This results in the following error:
error[E0308]: mismatched types
--> src/main.rs:10:21
|
10 | |acc, task| acc.and_then(|_| task), // accumulator
| ^^^^^^^^^^^^^^^^^^^^^^ expected struct `futures::FutureResult`, found struct `futures::AndThen`
|
= note: expected type `futures::FutureResult<_, _>`
found type `futures::AndThen<futures::FutureResult<_, _>, futures::FutureResult<(), _>, [closure@src/main.rs:10:34: 10:42 task:_]>`
I probably approached this wrong, but I ran out of ideas.
source
share