I'm new golang. I write a parallel request code but sometimes occur wait a long time. Do you know any reason?
var wg sync.WaitGroup
guard := make(chan struct{}, 50)
for _, li := range results {
wg.Add(1)
guard <- struct{}{}
go func(){
defer func(){//I'm afraid some panic, so I use defer func, make sure it has done.
wg.Done()
<-guard
}()
//some biz code
//http requests
}()
}
wg.Wait()
I try print process number, observer number, always stuck the last process long time. I don't know the stuck reason. It can be finished, just stuck a long time in the last process.