Channels and select / Non-blocking receive with se

Run Settings
LanguageGo
Language Version
Run Command
package main import ( "fmt" "time" ) func main() { ch := make(chan int, 1) end: for { select { case n := <-ch: fmt.Printf("Received %d from a channel\n", n) break end default: fmt.Print("Channel is empty\n") ch <- 8 } // wait for channel to be filled with values // don't use time.Sleep() like that in production code time.Sleep(20 * time.Millisecond) } }
Editor Settings
Theme
Key bindings
Full width
Lines