Can't use await in an async function

here's the reproduce repo:

Your link is not working, I think your repo is private.

You are so quick, I just make it public

1 Like

You are trying to call an async function you annotated with #[tokio::main]. The main procedural macro desugars your function to a synchronous function, which is why you can't .await it. From the docs:

Note: This macro can be used on any function and not just the main function. Using it on a non-main function makes the function behave as if it was synchronous by starting a new runtime each time it is called. If the function is called often, it is preferable to create the runtime using the runtime builder so the runtime can be reused across calls.

Just remove the #[tokio::main] from file_uti and your code should work.

1 Like

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.