-
Notifications
You must be signed in to change notification settings - Fork 12
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
Simplifying amap usage #18
Comments
you can do this but you'd need to pass the TaskGroup into the amap, and wrap the returned AsyncGenerator with aclosing: async with anyio.create_task_group() as tg:
async with aclosing(amap(process, items, tg)) as aiter:
results = [result async for result in aiter] |
@graingert Well indeed, good point. The actual correct comparison would then be this… (Current situation) async with aiometer.amap(process, items) as aiter:
results = [result async for result in aiter] Compared to this… (Correct implementation of proposed idea) async with anyio.create_task_group() as tg:
async with aclosing(aiometer.amap(process, items, tg)) as aiter:
results = [result async for result in aiter] Which instantaneously seems like we don't want I think we can close this then? |
|
Reading through the docs it came to my mind that the
async with
usage ofamap
doesn’t “look necessary” from a UX perspective.When using it we always have to do two things:
async with
(looks like an implementation detail)async for
As a user really only care about the second operation.
So what if we moved
async with
inside the implementation of amap, so that users can just do...The text was updated successfully, but these errors were encountered: