github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2012/concurrency/support/changoboring.go (about)

     1  // +build OMIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"math/rand"
     8  	"time"
     9  )
    10  
    11  // START1 OMIT
    12  func main() {
    13  	c := make(chan string)
    14  	go boring("boring!", c)
    15  	for i := 0; i < 5; i++ {
    16  		fmt.Printf("You say: %q\n", <-c) // Receive expression is just a value. // HL
    17  	}
    18  	fmt.Println("You're boring; I'm leaving.")
    19  }
    20  // STOP1 OMIT
    21  
    22  // START2 OMIT
    23  func boring(msg string, c chan string) {
    24  	for i := 0; ; i++ {
    25  		c <- fmt.Sprintf("%s %d", msg, i) // Expression to be sent can be any suitable value. // HL
    26  		time.Sleep(time.Duration(rand.Intn(1e3)) * time.Millisecond)
    27  	}
    28  }
    29  // STOP2 OMIT
    30