Commit 87f3eca1 by 杨树贤

不要复用ctx

parent 840cd331
Showing with 12 additions and 3 deletions
......@@ -75,10 +75,13 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
idsToProcess := make([]string, len(zyGoodsId))
copy(idsToProcess, zyGoodsId)
// 在启动协程前,复制一份 context
ctxCopy := ctx.Copy()
go func(ctx_in *gin.Context, goodsIds_in []string, chs_in chan sync.Map) {
defer wg.Done()
zyService.ZyGoodsDetail(ctx_in, goodsIds_in, chs_in)
}(ctx, idsToProcess, ch)
}(ctxCopy, idsToProcess, ch)
zyGoodsId = zyGoodsId[:0]
}
......@@ -91,10 +94,13 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
idsToProcess := make([]string, len(lyGoodsId))
copy(idsToProcess, lyGoodsId)
// 在启动协程前,复制一份 context
ctxCopy := ctx.Copy()
go func(ctx_in *gin.Context, goodsIds_in []string, chs_in chan sync.Map) {
defer wg.Done()
lyService.LyGoodsDetail(ctx_in, goodsIds_in, chs_in)
}(ctx, idsToProcess, ch)
}(ctxCopy, idsToProcess, ch)
lyGoodsId = lyGoodsId[:0]
}
......@@ -121,10 +127,13 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
idsToProcess := make([]string, len(lyGoodsId))
copy(idsToProcess, lyGoodsId)
// 在启动协程前,复制一份 context
ctxCopy := ctx.Copy()
go func(ctx_in *gin.Context, goodsIds_in []string, chs_in chan sync.Map) {
defer wg.Done()
lyService.LyGoodsDetail(ctx_in, goodsIds_in, chs_in)
}(ctx, idsToProcess, ch)
}(ctxCopy, idsToProcess, ch)
}
// 开启一个协程,等待所有任务完成,然后关闭channel
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment