The Python docs give this code example:
import asyncio
async def main():
print('Hello ...')
await asyncio.sleep(1)
print('... World!')
asyncio.run(main())
Why is main
called inside the asyncio.run()
(and in other asyncio functions like asyncio.gather()
)?
It confuses me, because in JavaScript, we do things like document.addEventListener('click', someFunction)
– we pass someFunction
, not its result.