closing a channel

Calling close on a channel to announce that no more values will be sent, which lets receivers stop ranging over it.

In more detail

Only the sender should close, and only once: sending on or closing an already closed channel panics. Receivers can keep reading the remaining buffered values, then get the zero value with ok set to false. A for range loop over a channel ends when it is closed.

Example

wait.Wait()
close(results)

Related terms

Taught in

References