golang 简单的 channel

 

package main

import(
        "fmt"
        "os"
        "bufio"
        )


func main(){
in :=make(chan string)

out :=make(chan string)

reader := bufio.NewReader(os.Stdin)


        go func(){
                for {
                        a:= <-in
                        out <- a
                        fmt.Println("in",a)
                }
        }()

        go func(){
                for {

                        b:=<-out
                        fmt.Println("out",b)
                    }

        }()

for{
        line, _:= reader.ReadString('\n')
        fmt.Println("<----------------------------->")
        in <- line
}





}



你可能感兴趣的:(golang 简单的 channel)