fork download
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6. ch := make(chan int) // канал
  7. for i := 1; i < 5; i++ {
  8. go work(ch)
  9. }
  10. for i := 1; i < 10; i++ {
  11. fmt.Println("Got:", <-ch)
  12. }
  13. fmt.Println("The End")
  14. }
  15.  
  16. func work(ch chan int) {
  17. for k := 1; k <= 3; k++ {
  18. ch <- k
  19. }
  20. }
Success #stdin #stdout 0s 5516KB
stdin
Standard input is empty
stdout
Got: 1
Got: 2
Got: 3
Got: 1
Got: 2
Got: 3
Got: 1
Got: 2
Got: 3
The End