Skip to content

Instantly share code, notes, and snippets.

@YabZhang
Created May 21, 2020 17:54
Show Gist options
  • Select an option

  • Save YabZhang/425b4385babbf73ba5762f70e656d5f1 to your computer and use it in GitHub Desktop.

Select an option

Save YabZhang/425b4385babbf73ba5762f70e656d5f1 to your computer and use it in GitHub Desktop.
timeout_refine
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