package main
import (
"fmt"
"sync"
"time"
)
func main() {
wg := sync.WaitGroup{}
maxChannel := make(chan struct{}, 10000)
fmt.Println("begin")
for i:=0; i<=1000; i++ {
wg.Add(1)
maxChannel<- struct{}{}
go func(i int) {
defer func() {
wg.Done()
<-maxChannel
}()
time.Sleep(time.Second)
fmt.Println(i)
}(i)
}
wg.Wait()
fmt.Println("end")
}