Keyword
Go select keyword
Chooses a channel communication that can proceed. If several can proceed, one is chosen pseudo-randomly; default handles no-ready cases. Without default it waits; nil channels never become ready. Example has one ready receive.
Formal Syntax & Structure
go syntaxgo
select { case communication: statements; default: statements }Working Example
Example Snippetgo
package main
import "fmt"
func main() { ch := make(chan string, 1) ch <- "job" select { case v := <-ch: fmt.Println(v) default: fmt.Println("empty") }}