Skip to content

Commit

Permalink
更新0512
Browse files Browse the repository at this point in the history
  • Loading branch information
ffhelicopter committed May 12, 2019
1 parent 2f22ade commit cd26ee5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
24 changes: 24 additions & 0 deletions source-code/ch14/1/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import "fmt"

func main() {

switch a := 1; {
case a == 1:
fmt.Println("The integer was == 1")
fallthrough
case a == 2:
fmt.Println("The integer was == 2")
case a == 3:
fmt.Println("The integer was == 3")
fallthrough
case a == 4:
fmt.Println("The integer was == 4")
case a == 5:
fmt.Println("The integer was == 5")
fallthrough
default:
fmt.Println("default case")
}
}
25 changes: 25 additions & 0 deletions source-code/ch14/2/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"fmt"
"time"
)

func main() {
var c1, c2, c3 chan int
var i1, i2 int
select {
case i1 = <-c1:
fmt.Printf("received ", i1, " from c1\n")
case c2 <- i2:
fmt.Printf("sent ", i2, " to c2\n")
case i3, ok := (<-c3):
if ok {
fmt.Printf("received ", i3, " from c3\n")
} else {
fmt.Printf("c3 is closed\n")
}
case <-time.After(time.Second * 3): //超时退出
fmt.Println("request time out")
}
}

0 comments on commit cd26ee5

Please sign in to comment.