Asynchronous setup and teardown for @value decorator.
Value decorator should handle async generators.
As it turns out contextlib.AsyncExitStack can do all the cleanup job for us. All we need to do is register all context managers in it.
class Container(Injector):
app = App
@value
async def db_connection(pool):
connection = await pool.aquire()
yield connection
await connection.release()
async with Container as initialized:
await initialized.app.process()
In the case of asyncio explicit loop should be added to the injection scope and required by value decorated function.
See #114
Hey @proofit404, I was exploring the idea of using the value decorator to handle async generators, but it appears that this feature hasn't been implemented yet. Do you have any estimates on when this might be available for us to use? I'm really excited about the potential benefits of this feature! Thanks!
Hello @balazser
At the moment we have a newborn so I can't do estimations on my open source work.
But when I would come back to the dependencies project, this feature would be one of the highest priorities.
I think my answer does not help you much :sweat_smile:
Have a good day :cocktail: :palm_tree:
Regards, Josiah.