go go + select language understanding

// select the language coroutines go inside the code there is the role of blocking back select continues to run, but when the case get to select data, coroutine inside the code is not stopped, he will continue to run the
Package Penalty for main Import ( "FMT" "Time" ) FUNC main () { fmt.Println ( "timeout setting") var CH Chan String Go FUNC () { time.sleep (time.Second *. 3) fmt.Println ( "dasfsdfaf") / / here still running } () SELECT { Case RES: = <-CH: fmt.Println (RES) return Case <-time.After (time.Second * 2): // over time even after 2 seconds, coroutine code or run inside the time.sleep (time.Second *. 3) fmt.Println ( "timeout") } }

 

Guess you like

Origin www.cnblogs.com/MyUniverse/p/11234984.html