File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -172,6 +172,27 @@ msg = await ch.async_receive()
172172
173173** Raises:** ` ChannelClosed ` when the channel is closed.
174174
175+ #### ` close() `
176+
177+ Close the channel from Python. Wakes any waiting receivers.
178+
179+ ``` python
180+ ch.close() # Signal no more data will be sent
181+ ```
182+
183+ Safe to call multiple times.
184+
185+ #### Context Manager
186+
187+ Channels support the ` with ` statement for automatic cleanup:
188+
189+ ``` python
190+ with Channel(channel_ref) as ch:
191+ for msg in ch:
192+ process(msg)
193+ # channel automatically closed on exit
194+ ```
195+
175196#### Iteration
176197
177198``` python
@@ -461,6 +482,15 @@ def process_bytes(channel_ref):
461482
462483 # Send bytes back
463484 ch.send_bytes(b " response data" )
485+
486+ # Close when done
487+ ch.close()
488+
489+ # Or use context manager for automatic cleanup
490+ with ByteChannel(channel_ref) as ch:
491+ for chunk in ch:
492+ process(chunk)
493+ # channel automatically closed
464494```
465495
466496### Async Python API
You can’t perform that action at this time.
0 commit comments