injectable icon indicating copy to clipboard operation
injectable copied to clipboard

Support for async injectables

Open roo-oliv opened this issue 4 years ago • 6 comments
trafficstars

It's currently not ideal to use this library together with Python's async/await.

We should support asynchronous constructors and factories.

Async constructors are also a bigger problem since one cannot declare an async __init__ method without bending some snakes. This calls for ways to construct and/or setup an injectable other than relying solely on __init__.

roo-oliv avatar Aug 16 '21 23:08 roo-oliv

cool

Euraxluo avatar Aug 24 '21 08:08 Euraxluo

What do you think of PEP593 typing.Annotated i think you can add some attr annotated

Euraxluo avatar Aug 25 '21 04:08 Euraxluo

What do you think of PEP593 typing.Annotated i think you can add some attr annotated

Hi @Euraxluo, thanks for the bringing this to attention! Indeed I'm thinking of how to best support typing.Annotated in this framework. I do believe though that this should be discussed in a separated issue from this one regarding async injectables.

roo-oliv avatar Aug 26 '21 13:08 roo-oliv

any updates on planning to support async dependencies?

aryaniyaps avatar Dec 13 '23 01:12 aryaniyaps

any updates on planning to support async dependencies?

I'll start working on some other issues listed in this project where there is already a clear implementation path but we can talk about this issue to find a good solution so I can work on it right after.

@aryaniyaps it would be great to hear from you if you have any specific suggestions or external examples to enrich this discussion. Or even just your need so we can have a clear set of scenarios we want to cover.

roo-oliv avatar Dec 13 '23 13:12 roo-oliv

I don't have any specific suggestions in mind, but async support would be nice as the python ecosystem has adapted more and more of the async await syntax

Off the top of my head, the framework could use anyio to resolve the async dependencies by using a iscouroutine check, maybe? This way support is extended to multiple io backends like asyncio and trio!

aryaniyaps avatar Dec 14 '23 05:12 aryaniyaps