Our first example demonstrates how to close channels, which is useful for communicating completion to the channel’s receivers.
To run the program, save it as closing_channels.cr and use the Crystal compiler:
In Crystal, channels are closed using the close method. When a channel is closed, any further attempts to send on it will raise an exception. Receivers can use the receive? method to check if a channel is closed.
The concept of closed channels leads naturally to our next example: iterating over channels.