forked from ffhelicopter/Go42
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ffhelicopter
committed
May 12, 2019
1 parent
2f22ade
commit cd26ee5
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |