Skip to content

Instantly share code, notes, and snippets.

@aybabtme
Created January 27, 2014 16:48
Show Gist options
  • Save aybabtme/8652289 to your computer and use it in GitHub Desktop.
Save aybabtme/8652289 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"time"
)
func main() {
nobodyListening := make(chan struct{})
go func(sendMsg chan<- struct{}) {
time.Sleep(time.Second * 3)
sendMsg <- struct{}{}
}(nobodyListening)
for i := 0; i < 5; i++ {
select {
case <-nobodyListening:
log.Printf("Got a message")
default:
log.Printf("Nobody's listening!")
}
<-time.Tick(time.Second * 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment