Async combinators

Let's say I have an async fn which does some processing, and that processing entails handling Result types.

These Results of course call map, and_then, etc.

However, if I need to do more async stuff inside these combinators, it fails to compile.

Am I missing something fundamental here? Tried wrapping stuff in async blocks, fought the compiler a few ways for a bit of time before giving up and doing regular pattern matching.

You can't do async inside an ordinary closure. Since Result::and_then takes an ordinary closure, you cannot .await inside it.

is there an easy way to turn a Result<A,B> into some sort of impl Future<Output = Result<A,B>> ?

Yes, async move { the_result }, but I'm guessing that's not what you meant.

1 Like

not sure, would need to play around :slight_smile:

thanks again!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.