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

     1  // +build OMIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"time"
     8  )
     9  
    10  // START1 OMIT
    11  func main() {
    12  	c := make(chan string)
    13  	go f("three", 300*time.Millisecond, c) // HL
    14  	go f("six", 600*time.Millisecond, c)   // HL
    15  	go f("nine", 900*time.Millisecond, c)  // HL
    16  	for i := 0; i < 10; i++ {
    17  		fmt.Println("Received", <-c)
    18  	}
    19  	fmt.Println("Done.")
    20  }
    21  
    22  // STOP1 OMIT
    23  
    24  // START2 OMIT
    25  func f(msg string, delay time.Duration, c chan string) {
    26  	for i := 0; ; i++ {
    27  		c <- fmt.Sprintf("%s %d", msg, i) // Any suitable value can be sent. // HL
    28  		time.Sleep(delay)
    29  	}
    30  }
    31  
    32  // STOP2 OMIT