Is there a way to return early from a future combinator chain? For example, I'd like to return success if some condition holds, otherwise keep going down the chain.
I want to do something similar to this:
fn early_exit() -> impl Future<Item = u32, Error = String> {
ok::<u32, String>(42)
.and_then(some_function)
.and_then(another_function)
.and_then(|x| {
// return early if condition is satisfied
if some_condition(x) {
return ok::<u32, String>(42);
}
// Else pass it down the combinator chain for further transformations
else {
Ok(x)
}
})
.and_then(one_more_function)
.and_then(last_function)
}
I think this should be doable with async
/await
, but is there a good way to do this with futures 0.1?