GO by example, part 4

This commit is contained in:
2022-01-11 14:50:17 +01:00
parent c5983176c5
commit 5d7e654fa1
10 changed files with 428 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
package main
import "fmt"
func main() {
// iterate over values received from a channel
// here iterate over 2 values in the queue channel
queue := make(chan string, 2)
queue <- "one"
queue <- "two"
close(queue)
// range iterates over each element as its received from queue
for elem := range queue {
fmt.Println(elem)
}
// also shows that its possible to close a non-empty channel but still have the remaining values be received
}