question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to deal with async resources

See original GitHub issue

Hi, 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:closed
  • Created 3 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
rmk135commented, Dec 14, 2020

Update: this will take a few extra days. I’ve upgraded Factory and Callable providers to make async injections properly and added tests for that. That was the complex part. Now need to deal with Singleton and other providers.

2reactions
rmk135commented, Jan 11, 2021

I have published version 4.6 that supports async resources and adds async mode. See the docs for more info:

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found