__await__
method defines the behavior of class with await
is called on class object.
The await() magic method defines the behavior of an awaitable object. An awaitable object is used to implement asynchronous behavior in Python.
__await__
is not async
method but it returns closure __await__
from a closure method.
import asyncio
from collections.abc import Awaitable
class Trigger(Awaitable):
def __init__(self):
pass
def __await__(self):
async def c():
print("Do async stuff here")
return self
return c().__await__()
class Edge(Trigger):
pass
async def main():
print("main")
await Edge()
print("done")
asyncio.run(main())