We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4e43193 commit 69a50bdCopy full SHA for 69a50bd
1 file changed
module_asyncio/samples/await_awaitable.py
@@ -0,0 +1,27 @@
1
+import asyncio
2
+from typing import Awaitable, Generator
3
+
4
5
+class MyAwaitable(Awaitable):
6
+ def __init__(self):
7
+ print("init")
8
9
+ def __await__(self) -> Generator:
10
+ async def closure():
11
+ print("await")
12
+ return self
13
14
+ return closure().__await__()
15
16
+ async def method(self):
17
+ print("method")
18
19
20
+async def main():
21
+ m = MyAwaitable()
22
+ obj = await m
23
+ await obj.method()
24
25
26
+if __name__ == "__main__":
27
+ asyncio.get_event_loop().run_until_complete(main())
0 commit comments