local ths = {}
local start_time = ngx_now()
ths[1] = spawn(work, 0.2) -- change to 0.05 will get 50ms timeout for the wait below
ths[2] = spawn(work, 0.3)
ths[3] = spawn(work, 0.4)
local ok, err = sema:wait(0.1)
if not ok then
if err ~= "timeout" then
ngx_say("failed to wait, err: ", err)
return
end
end
-- just for demo the status
for i = 1,3 do
ngx_say("thread ", i, " status: ", coroutine.status(ths[i]))
end
ngx.update_time()
local end_time = ngx_now()
ngx_say("elapse: ", end_time - start_time, "ms")
}
}
```