Guest User

Untitled

a guest
Jan 15th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import asyncio
  2. import abc
  3. import contextlib
  4. from typing import AsyncIterator
  5.  
  6.  
  7. class Test(abc.ABC):
  8. @abc.abstractmethod
  9. async def request(self) -> AsyncIterator:
  10. pass
  11.  
  12.  
  13. class SubTest(Test):
  14. @contextlib.asynccontextmanager
  15. async def request(self) -> AsyncIterator:
  16. await asyncio.sleep(1)
  17. yield 1
  18. await asyncio.sleep(1)
  19.  
  20.  
  21. async def main():
  22. obj = SubTest()
  23. async with obj.request() as res:
  24. print(res)
  25.  
  26.  
  27. asyncio.run(main())
Add Comment
Please, Sign In to add comment