Can't get values from async block

I just want to collect the result of the try_join! -- which as I understand should be either a single Error or tuple of Results. I have tried a lot of combinations, but I can't seem to get there. It seems like the async block is not actually executed?

Minimal example:

Two errors:

  1. You are not awaiting the async {} block. The literal type of any async expression is a Future<Output = T> wrapping the type of the underlying expression.
  2. Ok(_) has only a single field. It may be a tuple, but there still aren't 2 fields in a Result<(_, _), _>::Ok.

This compiles. It can also be simplified.

2 Likes

Thanks, indeed that does compile... you made main() async... is it possible to do it from a non async function? Basically I want the program to wait until it gets the values.

Can you do it without changing main()?

The context that includes try_join must be async because the macro expands to an expression that contains .await. There's no way around that.

You can technically remove the async fn main() {}, and #[tokio::main], but do note that doing so only makes you replicate the behavior of the exact same thing by hand. main is not actually async in either case – it's just that the tokio authors probably thought it was cute to indicate that the #[tokio::main] macro introduces an async context, and they wanted to be explicit about it. There's no good reason for doing all that work manually, but it can be done.

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.