Thanks. On Sun, Jan 15, 2017 at 2:05 AM, Dave Cheney <d...@cheney.net> wrote: > When your program blocks, hit control-\ and you'll get a stack trace of > every running goroutine, the ones blocked inside downPart will point to the > place they are blocked. > > > On Sunday, 15 January 2017 05:33:25 UTC+11, vyasgir...@gmail.com wrote: >> >> I am implementing a multi part file downloader and I need help to find the >> blocking element in the following piece of code. >> >> >> func downPart(wg *sync.WaitGroup, url string, dataChan chan []byte, >> range1, range2 int) { >> >> >> defer wg.Done() >> client := new(http.Client) >> req, _ := http.NewRequest("GET", url, nil) >> >> >> req.Header.Set("Range", strconv.Itoa(range1)+"-"+strconv.Itoa(range2)) >> data, err := client.Do(req) >> if err != nil { >> fmt.Println(err) >> return >> } >> dataByte := new(bytes.Buffer) >> dataByte.ReadFrom(data.Body) >> fmt.Println("Done") >> >> >> dataChan <- dataByte.Bytes() >> } >> func multiDownload(url string, length int) bool { >> var wg sync.WaitGroup >> >> >> x := 4 >> split := length / x >> fmt.Println(length) >> dataChan := make([]chan []byte, x) >> for i := 0; i < x; i++ { >> wg.Add(1) >> >> >> range1 := i * split >> range2 := (i+1)*split - 1 >> if range2 == length-2 { >> range2 = length >> } >> fmt.Println(len(dataChan), range1, range2) >> go downPart(&wg, url, dataChan[i], range1, range2) >> } >> >> >> var data []byte >> wg.Wait() >> >> >> for i := 0; i < x; i++ { >> fmt.Println("waiting") >> data = <-dataChan[i] >> fmt.Println(data) >> } >> return true >> >> }
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.