【发布时间】:2018-07-07 23:35:47
【问题描述】:
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 请求?
【问题讨论】: