大佬们go并发有个问题想请教一下-关于1秒钟并发请求N个api的问题

xiaolaodi · · 1556 次点击
``` { //每秒并发数量 max := 50 i := 0 j := 0 l := 0 tmp := make([] string, max) if (len(last_zip_code) == 6) { if (last_zip_code[0:2] == math) { i, _ = strconv.Atoi(last_zip_code[2:6]) } } zips := make([]string, 10000) for i < 10000 { str_i := fmt.Sprintf("%04d", i) zip := math + str_i if zip != "" { zips[j] = zip } else { zips = append(zips[:j], zips[j+1:]...) } i ++ j ++ } timeout := time.NewTicker(time.Millisecond).C for _, v := range zips { if (v != "") { last := tmp[len(tmp)-1] if (last != "") { loop: for { select { case <-timeout: sync := make(chan bool) go func(tmp []string) { run(tmp, info) sync <- true }(tmp) <-sync break loop } } l = 0 tmp = make([] string, max) } tmp[l] = v } l++ } } ```
#5
更多评论
用go 协程去请求api
#1
哥们 我也这么想的,但是似乎不对。
#2