sdf
This commit is contained in:
parent
95f257a4d0
commit
1a9bc04ef9
|
|
@ -1,18 +1,39 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func Route(i int, ch chan<- int) {
|
||||
ch <- i
|
||||
type Res struct {
|
||||
num int
|
||||
name string
|
||||
}
|
||||
|
||||
func Route(i int,k string, ch chan<- Res) {
|
||||
ch <- Res{
|
||||
num: i,
|
||||
name: k,
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
ch := make(chan int)
|
||||
ch := make(chan Res,20)
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for i:= range 10 {
|
||||
go Route(i, ch)
|
||||
for _,k := range []string{"thr1","thr2"} {
|
||||
wg.Add(1)
|
||||
go func () {
|
||||
defer wg.Done()
|
||||
Route(i, k, ch)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
close(ch)
|
||||
|
||||
for i := range ch {
|
||||
fmt.Println(i)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user