mv _demo/chandemo
This commit is contained in:
21
_cmptest/_chandemo/chan.go
Normal file
21
_cmptest/_chandemo/chan.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
c1 := make(chan string)
|
||||
c2 := make(chan string, 1)
|
||||
go func() {
|
||||
c1 <- "ch1"
|
||||
}()
|
||||
go func() {
|
||||
c2 <- "ch2"
|
||||
}()
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
select {
|
||||
case msg1 := <-c1:
|
||||
println(msg1)
|
||||
case msg2 := <-c2:
|
||||
println(msg2)
|
||||
}
|
||||
}
|
||||
}
|
||||
19
_cmptest/_timeout/timer.go
Normal file
19
_cmptest/_timeout/timer.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var c chan int
|
||||
|
||||
func handle(int) {}
|
||||
|
||||
func main() {
|
||||
select {
|
||||
case m := <-c:
|
||||
handle(m)
|
||||
case <-time.After(10 * time.Second):
|
||||
fmt.Println("timed out")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user