Skip to content

Instantly share code, notes, and snippets.

@makeittotop
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save makeittotop/60271e24041793c47081 to your computer and use it in GitHub Desktop.

Select an option

Save makeittotop/60271e24041793c47081 to your computer and use it in GitHub Desktop.
go non blocking example
package main
import "fmt"
func main() {
messages := make(chan string)
signals := make(chan bool)
select {
case msg := <-messages:
fmt.Println("received message", msg)
default:
fmt.Println("no message received")
}
msg := "hi"
select {
case messages <- msg:
fmt.Println("sent message", msg)
default:
fmt.Println("no message sent")
}
select {
case msg := <-messages:
fmt.Println("received message", msg)
case sig := <-signals:
fmt.Println("received signal", sig)
default:
fmt.Println("no activity")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment