In a previous example we saw how |
|
package main
|
|
import "fmt"
|
|
func main() {
|
|
We’ll iterate over 2 values in the |
queue := make(chan string, 2)
queue <- "one"
queue <- "two"
close(queue)
|
This |
for elem := range queue {
fmt.Println(elem)
}
}
|
$ go run range-over-channels.go
one
two
|
|
This example also showed that it’s possible to close a non-empty channel but still have the remaining values be received. |
Previous example: Closing Channels.
Next example: Timers.