Here's an excerpt from a piece of concurrent code I like, an unpublished interactive game of life. The select near the bottom has only two cases but it is perhaps instructive. I leave its analysis to the reader.
-rob var kbdC chan of rune = ... // events from keyboard var ticker = time.NewTicker(*deltaTFlag) ... pauseC := make(chan int) go func() { for { switch <-kbdC { case 'q': os.Exit(0) case ' ': pauseC <- 1 } } }() gen := 0 for gen = 1; ; gen++ { b.draw(display, *cellSizeFlag) changed := b.step() if !changed { break } select { case <-ticker.C: case <-pauseC: <-pauseC } } fmt.Fprintln(os.Stderr, "stable after", gen, "generations") select {} } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOXNBZS11bKz%2B95gUXstgHHrgDRFoTWdm5kmNBriDpoxNz%3DWXQ%40mail.gmail.com.