github.com/reapchain/go-reapchain@v0.2.15-0.20210609012950-9735c110c705/cmd/select/select.go (about) 1 2 // Go program to illustrate the 3 // concept of select statement 4 package main 5 6 import("fmt" 7 "time") 8 9 // function 1 10 func portal1(channel1 chan string) { 11 12 time.Sleep(9*time.Second) 13 channel1 <- "Welcome to channel 1" 14 } 15 16 // function 2 17 func portal2(channel2 chan string) { 18 19 time.Sleep(3*time.Second) 20 channel2 <- "Welcome to channel 2" 21 } 22 23 // main function 24 func main(){ 25 26 // Creating channels 27 R1:= make(chan string) 28 R2:= make(chan string) 29 30 // calling function 1 and 31 // function 2 in goroutine 32 go portal1(R1) 33 go portal2(R2) 34 35 select{ 36 37 // case 1 for portal 1 38 case op1:= <- R1: 39 fmt.Println(op1) 40 41 // case 2 for portal 2 42 case op2:= <- R2: 43 fmt.Println(op2) 44 } 45 46 }