Created
May 21, 2020 17:54
-
-
Save YabZhang/425b4385babbf73ba5762f70e656d5f1 to your computer and use it in GitHub Desktop.
timeout_refine
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| ) | |
| func main() { | |
| fmt.Println("start...", time.Now()) | |
| timeout := time.After(1 * time.Second) | |
| ch := make(chan string) | |
| select { | |
| case msg := <- ch: | |
| fmt.Println("got msg from ch...", msg) | |
| case <-timeout: | |
| fmt.Println("timeout!") | |
| } | |
| fmt.Println("end...", time.Now()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment