Advertisement
Guest User

Untitled

a guest
Sep 14th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import asyncio
  2.  
  3. class User:
  4.     def __init__(self):
  5.         self.id = None
  6.         self.username = None
  7.  
  8.     @classmethod
  9.     async def create(cls, id):
  10.       user = cls()
  11.       user.id = id
  12.       user.username = await get_username(id)
  13.       return user
  14.  
  15.  
  16. async def main():
  17.   user = await User.create(1)
  18.   print(user.username)
  19.  
  20. async def get_username(id):
  21.     await asyncio.sleep(1)
  22.     return "shiro"
  23.  
  24. loop = asyncio.get_event_loop()
  25. loop.run_until_complete(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement