github.com/code-reading/golang@v0.0.0-20220303082512-ba5bc0e589a3/coding/runtime/01-goroutine.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  )
     7  
     8  func goroutineA(a <-chan int) {
     9  	fmt.Println("G1 received data: ", <-a)
    10  }
    11  
    12  func goroutineB(b <-chan int) {
    13  	fmt.Println("G2 received data: ", <-b)
    14  }
    15  
    16  func main() {
    17  	ch := make(chan int)
    18  	go goroutineA(ch)
    19  	go goroutineB(ch)
    20  	ch <- 3
    21  	time.Sleep(time.Second)
    22  }