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

First pass at iterable Emissions objects #72

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions qtrio/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ async def aclose(self):
"""
return await self.send_channel.aclose()

def __aiter__(self):
return self.channel.__aiter__()


@async_generator.asynccontextmanager
async def open_emissions_channel(
Expand Down
4 changes: 2 additions & 2 deletions qtrio/_tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ async def test(request):
await emissions.aclose()

async with emissions.channel:
async for emission in emissions.channel:
async for emission in emissions:
[value] = emission.args
results.append(value)

Expand Down Expand Up @@ -774,7 +774,7 @@ async def test(request):
await emissions.aclose()

async with emissions.channel:
async for emission in emissions.channel:
async for emission in emissions:
[value] = emission.args
results.append(value)

Expand Down
2 changes: 1 addition & 1 deletion qtrio/examples/_tests/test_crossingpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setText(self, *args, **kwargs):
results = []

async def user():
async for emission in emissions.channel:
async for emission in emissions:
[text] = emission.args
results.append(text)

Expand Down
2 changes: 1 addition & 1 deletion qtrio/examples/emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def main(window=None):
async with qtrio.enter_emissions_channel(signals=signals) as emissions:
window.show()

async for emission in emissions.channel:
async for emission in emissions:
if emission.is_from(window.decrement.clicked):
window.decrement_count()
elif emission.is_from(window.increment.clicked):
Expand Down