Closing a channel indicates that no more values will be sent on it. This can be useful to communicate completion to the channel’s receivers. |
|
|
|
|
|
In this example we’ll use a |
|
Here’s the worker goroutine. It repeatedly receives
from |
|
This sends 3 jobs to the worker over the |
|
We await the worker using the synchronization approach we saw earlier. |
|
Reading from a closed channel succeeds immediately,
returning the zero value of the underlying type.
The optional second return value is |
|
|
|
The idea of closed channels leads naturally to our next
example: |
Next example: Range over Channels.