问了 ds, 解释的有点 get 不到,求大佬详细解释下
package main
import (
"fmt"
"sync"
)
func main() {
var wg sync.WaitGroup
prev := make(chan struct{})
current := make(chan struct{})
prev = current
for id := 1; id <= 10; id++ {
wg.Add(1)
next := make(chan struct{})
go func(id int, prev <-chan struct{}, next chan<- struct{}) {
defer wg.Done()
<-prev
fmt.Println(id)
if id < 10 {
close(next)
}
}(id, prev, next)
prev = next
}
close(current)
wg.Wait()
}