在channel 和gorutine的联合使用中,select的结合使用也越来越多
1 package main 2 import ( 3 "fmt" 4 ) 5 func onedream(index int,value chan int){ 6 for{ 7 value<-index 8 } 9 } 10 11 12 func main(){ 13 var exit1=make(chan int) 14 var exit2=make(chan int) 15 go onedream(5,exit1) 16 go onedream(7,exit2) 17 for{ 18 19 select{ 20 case a:=<-exit1: 21 fmt.Println("result is ",a) 22 case b:=<-exit2: 23 fmt.Println("result is ",b) 24 } 25 } 26 27 28 }