Skip to content

Add close() method to Channel and ByteChannel#37

Merged
benoitc merged 2 commits intomainfrom
feature/channel-close-method
Mar 17, 2026
Merged

Add close() method to Channel and ByteChannel#37
benoitc merged 2 commits intomainfrom
feature/channel-close-method

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Mar 17, 2026

Summary

  • Add close() method to Channel and ByteChannel Python classes
  • Add context manager support (with statement) for automatic cleanup
  • Uses existing channel_close() C function exposed via new erlang._channel_close() binding

Usage

# Explicit close
channel.close()

# Context manager (auto-close on exit)
with Channel(ref) as ch:
    for msg in ch:
        process(msg)
# channel automatically closed

# Erlang detects closure
case py_channel:recv(Channel) of
    {ok, Data} -> process(Data);
    {error, closed} -> channel_was_closed
end.

benoitc added 2 commits March 17, 2026 22:15
Python can now close channels explicitly:
  channel.close()
  byte_channel.close()

Also adds context manager support:
  with Channel(ref) as ch:
      for msg in ch:
          process(msg)
  # channel automatically closed
@benoitc benoitc merged commit 6d12c7f into main Mar 17, 2026
11 checks passed
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

Successfully merging this pull request may close these issues.

1 participant