blob: 9e16caf9359e55075f22faeb18a03cddb723cef1 [file] [log] [blame]
// +build ignore,OMIT
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
// START1 OMIT
quit := make(chan bool) // HL
c := boring("Joe", quit)
for i := rand.Intn(10); i >= 0; i-- { fmt.Println(<-c) }
quit <- true // HL
// STOP1 OMIT
}
func boring(msg string, quit <-chan bool) <-chan string {
c := make(chan string)
go func() { // HL
for i := 0; ; i++ {
time.Sleep(time.Duration(rand.Intn(1e3)) * time.Millisecond)
// START2 OMIT
select {
case c <- fmt.Sprintf("%s: %d", msg, i):
// do nothing
case <-quit: // HL
return
}
// STOP2 OMIT
}
}()
return c
}