How to deal with async resources
See original GitHub issueHi, for my usecase I want to use aio_pika
And my singleton resource connection is created via:
connection = await connect(
"amqp://guest:guest@localhost/", loop=loop
)
and shutdown via
await connection.close()
but it looks like something like this is not supported yet:
async def aio_pika_connection():
connection = await connect(
"amqp://guest:guest@localhost/", loop=loop
)
yield connection
await connection.close()
class Container(containers.DeclarativeContainer):
config = providers.Configuration()
aio_pika_connection= providers.Resource(
aio_pika_connection
)
Any hints how to deal with this?
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Understanding Async Resources with Async Hooks
Async resources are nothing but objects that are used to keep track of asynchronous operations. Therefore, they are naturally associated with a ...
Read more >Async/Await - Best Practices in Asynchronous Programming
To summarize this first guideline, you should prefer async Task to async void. Async Task methods enable easier error-handling, composability and testability.
Read more >Resources On Async Tasks - InfoQ
Async Tasks, included in the Task Parallel Library, is a great way to write asynchronous code in – we look at a few...
Read more >How to deal with asynchronous code in JavaScript
Programming languages like C, Java, C#, PHP, Go, Ruby, Swift and Python are all synchronous by default, some of them handle async by...
Read more >How to use promises - Learn web development | MDN
With a promise-based API, the asynchronous function starts the operation and returns a Promise object. You can then attach handlers to this ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Update: this will take a few extra days. I’ve upgraded
Factory
andCallable
providers to make async injections properly and added tests for that. That was the complex part. Now need to deal withSingleton
and other providers.I have published version
4.6
that supports async resources and adds async mode. See the docs for more info: