Nice writeup, but it raised some questions: In your notification example, how would you get back a…
Péter Vajda

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 await your 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.Queue if you have to go across threads.
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.