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请求?
https://stackoverflow.com/questions/51223062
复制相似问题