Skip to content
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

async hell #13

Closed
kootenpv opened this issue Oct 24, 2016 · 1 comment
Closed

async hell #13

kootenpv opened this issue Oct 24, 2016 · 1 comment

Comments

@kootenpv
Copy link

async def fetch(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as res:
            return res

Might I be the first to call this "async hell" lol?

Is there really no other way to do this?

@tomas-fp
Copy link

tomas-fp commented Oct 24, 2016

You gonna love "async hell" so far than "callback hell", trust me :D

That's an isolated representative example, but you have multiple alternatives to avoid too nested statements, such as do not use async context managers (but that would make more boilerplate code), reuse the same sessions instead of create/destroying one.

A possible alternative passing the session instance and returning the response, but you should manually close things manually:

async def fetch(url, session):
  return await session.get(url)

@h2non h2non closed this as completed Oct 24, 2016
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

No branches or pull requests

3 participants