28 lines
397 B
Go
28 lines
397 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func count(start, end int, ch chan int) {
|
|
for i := start; i <= end; i++ {
|
|
ch <- i
|
|
}
|
|
close(ch)
|
|
}
|
|
|
|
func printCh(ch chan int) {
|
|
for i := 0; i < 5; i++ {
|
|
fmt.Println(<-ch)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
channel1to5 := make(chan int)
|
|
channel6to10 := make(chan int)
|
|
|
|
go count(1, 10, channel1to5)
|
|
go count(6, 10, channel6to10)
|
|
|
|
printCh(channel1to5)
|
|
printCh(channel6to10)
|
|
}
|