首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Goroutine超时

Goroutine超时
EN

Stack Overflow用户
提问于 2018-07-07 20:07:48
回答 0查看 1.1K关注 0票数 0
代码语言:javascript
复制
type Response struct {
  data   interface{}
  status bool
}

func Find() (interface{}, bool) {
  ch := make(chan Response, 1)

  go func() {
    data, status := findCicCode()
    ch <- Response{data: data, status: status}
  }()

  select {
  case response := <-ch:
    return response.data, response.status
  case <-time.After(50 * time.Millisecond):
    return "Request timed out", false
  }
}

所以,我有上面的功能。基本上,findCicCode()函数调用在内部对外部服务进行3次http调用。我在这里为这3个http调用添加了组合超时。在我的情况下不能单独超时。但如果超过超时,它仍然会在后台进行api调用。

我不确定这里是否有goroutine漏洞。如果超时,有没有办法取消这些https请求?

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51223062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档