Created
November 9, 2017 15:10
-
-
Save filinvadim/539f5f06b642e15245948665aa307379 to your computer and use it in GitHub Desktop.
Make python object fully async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
class _AsyncObject(object): | |
"""Inheriting this class allows you to define an async __init__. | |
So you can create objects by doing something like `await MyClass(params)` | |
""" | |
@asyncio.coroutine | |
def __new__(cls, *a, **kw): | |
instance = super().__new__(cls) | |
yield from instance.__init__(*a, **kw) | |
return instance | |
@asyncio.coroutine | |
def __init__(self): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment