await Is Not a Context Switch: Understanding Python's Coroutines vs Tasks — Mergify
If you're coming from JavaScript, the rule is simple:Every await always yields to the event loop.Every async function always returns a task (a Promise).The moment you write await, the runtime can schedule something else.
If you're coming from JavaScript, the rule is simple:
Every await always yields to the event loop.
Every async function always returns a task (a Promise).
The moment you write await, the runtime can schedule something else.
JavaScript: async function → always a task
C#: async → always a task
Java (Loom's VirtualThread)): async → always a task
Python: async def → only a coroutine; task creation is explicit