Skip to content
  • Sponsor
  • Notifications You must be signed in to change notification settings
  • Fork 321
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional version of Resources #756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cpvandehey
Copy link

It would be really useful to have a Resource type that is capable of having a sync init function with an async shutdown.

There are many scenarios where this is useful

Ex:

  1. Create an aiohttp client.
    session = aiohttp.ClientSession()

  2. Before closing the app, I want to await any hanging connections
    await session.close()

@cpvandehey cpvandehey changed the title Update resources.py Add additional version of Resources Oct 26, 2023
@ZipFile
Copy link
Contributor

ZipFile commented Jan 12, 2025

I do not really think we need specific variations of AsyncResource (sync init + async shutdown, async init + sync shutdown) because the way how async stuff works in Python. async def function that never awaits have performance of the regular generator (see docs on coroutines), since it never switches to the event loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants