def async_enterable(f):
@functools.wraps(f)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>class AsyncEnterableInstance:<EOL><INDENT>async def __aenter__(self):<EOL><INDENT>self.context = await f(*args, **kwargs)<EOL>return await self.context.__aenter__()<EOL><DEDENT>async def __aexit__(self, *args, **kwargs):<EOL><INDENT>await self.context.__aexit__(*args, **kwargs)<EOL><DEDENT>def __await__(self):<EOL><INDENT>return f(*args, **kwargs).__await__()<EOL><DEDENT><DEDENT>return AsyncEnterableInstance()<EOL><DEDENT>return wrapper<EOL>
Decorator. Bring coroutine result up, so it can be used as async context

::

    >>> async def foo():
    ...
    ...     ...
    ...     return AsyncContextInstance(...)
    ...
    ... ctx = await foo()
    ... async with ctx:
    ...
    ...     # do

::

    >>> @async_enterable
    ... async def foo():
    ...
    ...     ...
    ...     return AsyncContextInstance(...)
    ...
    ... async with foo() as ctx:
    ...
    ...     # do
    ...
    ... ctx = await foo()
    ... async with ctx:
    ...
    ...     # do