github.com/traefik/yaegi@v0.15.1/_test/select2.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  func main() {
     8  	c1 := make(chan string)
     9  	c2 := make(chan string)
    10  	a := 0
    11  
    12  	go func() {
    13  		toSend := "hello"
    14  		select {
    15  		case c2 <- toSend:
    16  			a++
    17  		}
    18  		c1 <- "done"
    19  	}()
    20  
    21  	for i := 0; i < 2; i++ {
    22  		select {
    23  		case msg1 := <-c1:
    24  			fmt.Println("received from c1:", msg1)
    25  		case msg2 := <-c2:
    26  			fmt.Println("received from c2:", msg2)
    27  		}
    28  	}
    29  	fmt.Println("Bye", a)
    30  }
    31  
    32  // Output:
    33  // received from c2: hello
    34  // received from c1: done
    35  // Bye 1