Skip to content

Commit a5f74b1

Browse files
committed
docs(example): start handlers, then call client.update() in streaming_events example
1 parent 89fc321 commit a5f74b1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

examples/streaming_events.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ async def print_output_changes() -> None:
2626
async for output_id, active in output_changes:
2727
print(f"Output {output_id} changed to {active}")
2828

29+
tasks = [
30+
asyncio.create_task(client.keepalive()),
31+
asyncio.create_task(print_events()),
32+
asyncio.create_task(print_state_changes()),
33+
asyncio.create_task(print_zone_changes()),
34+
asyncio.create_task(print_output_changes()),
35+
]
36+
2937
try:
30-
await asyncio.gather(
31-
client.keepalive(),
32-
print_events(),
33-
print_state_changes(),
34-
print_zone_changes(),
35-
print_output_changes(),
36-
)
38+
# Allow handlers to start, then request an initial state update.
39+
await asyncio.sleep(0)
40+
await client.update()
41+
await asyncio.gather(*tasks)
3742
finally:
43+
for t in tasks:
44+
t.cancel()
3845
await events.aclose()
3946
await state_changes.aclose()
4047
await zone_changes.aclose()

0 commit comments

Comments
 (0)