I played with it some time ago. Actually, original code with few changes works fine.
Here's example:
https://gist.github.com/germn/6b2f8a1afbfc322daa01365cacd1d9ad
Test it:
import asyncio
from acontextlib import acontextmanager
state = []
@acontextmanager
async def woohoo():
state.append(1)
yield 42
state.append(999)
async def main():
async with woohoo() as x:
assert state == [1]
assert x == 42
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Has anyone tried to build an asynchronous version of @contextmanager? Is it even possible... given the use of yield?
_______________________________________________ Async-sig mailing list Async-sig@python.org https://mail.python.org/mailman/listinfo/async-sig Code of Conduct: https://www.python.org/psf/codeofconduct/