Hacker News new | ask | show | jobs
by fluoridation 209 days ago
Doesn't this make await a no-op? In what way are async functions asynchronous if tasks do not run interleaved?
2 comments

They are async across operations that do 'yield', i.e. when the function eventually runs an i/o operation or sleep or similar. Those are the points where the functions can be interleaved. Simply awaiting another function is _not_ one of those points: await here only means the called function might yield to the scheduler at some point in its execution (it doesn't have to!), not that the calling function will yield immediately.
Isn't asyncio.sleep one of those functions? "other" should be able to appear between "parent before" and "parent after".
Yes, but not between "parent before" and "child start" (or between "child end" and "parent after")
Ah, OK. That makes sense.
Tasks are async funcs that have been spawned with asyncio.create_task or similar, which then schedules its execution. A timer of zero doesn't spawn anything so the coroutine just executes in the same frame as the caller so yes it essentially a noop.