Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- class User:
- def __init__(self):
- self.id = None
- self.username = None
- @classmethod
- async def create(cls, id):
- user = cls()
- user.id = id
- user.username = await get_username(id)
- return user
- async def main():
- user = await User.create(1)
- print(user.username)
- async def get_username(id):
- await asyncio.sleep(1)
- return "shiro"
- loop = asyncio.get_event_loop()
- loop.run_until_complete(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement