Skip to content

Commit 69a50bd

Browse files
committed
await awaitable object
1 parent 4e43193 commit 69a50bd

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)