1. 程式人生 > >Go Example--通道遍歷

Go Example--通道遍歷

package main

import (
    "fmt"
)

func main() {
    queue := make(chan string, 2)
    queue <- "one"
    queue <- "two"
    close(queue)

    //for range chan 知道通道關閉
    for elem := range queue {
        fmt.Println(elem)
    }
}