Closing a Channel
You saw in Chapter 21 that flows can complete, meaning they emit no more items. And flow termination can happen in a few different ways; in the case of the flow builder that accepts a lambda expression, the flow implicitly completes when the lambda expression returns.
Similarly, channels can close, so that no additional values can be sent or received through the channel. But the channels you have created so far have no way to implicitly close themselves. You need to explicitly call close on the channels when you are finished emitting items.
You will need two calls to close. The first close call will be on passengerNamesChannel. Closing this channel will allow your workers to complete. If this channel does not ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access