That varies quite a bit depending on what you’re doing and how you need to use the result that you’re waiting for. The main mechanisms to handle those situations are:
- If your calling a function that returns a result and you have to process that result (like in your example), wrap it in another async function and
awaityour async method in there, then do the processing.
- Use a callback function that your async method will execute when it finishes, passing the result there.
- Use shared storage. There are various thread-safe systems for this like
asyncio.Queueif you have to go across threads.