on the go way (四)select 的用法

在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 }

 

posted on 2016-03-22 16:22  AAAAAApple  阅读(189)  评论(0编辑  收藏  举报

导航