我要请求 10 个 url,因为这些接口并不一定是通的,所以我设置了 1.5 秒的链接超时。但是如果一个一个的请求,假如 10 个 url 都连接超时,这个接口就需要耗费 15 秒。怎么搞成并发的,一共就耗时 1.5 这种。 类似于 openresty 的这种,即使全失败最多耗时 1.5 秒。
local threads = {}
for k, server in ipairs(res) do
threads[k] = ngx.thread.spawn(check_status, server)
end
for i=1, #threads do
local ok, res = ngx.thread.wait(threads[i])
end
go 里面用哪个函数呢?