如何在 init_by_lua 中进行非阻塞调用

How to make non blocking call in init_by_lua

init_worker_by_lua_block {
  ....
  ngx.timer.every(10, MyFunction)
}

function MyFunction()
  local response = requests.get { url = url, headers = h }. 
  ...

其中 MyFunction 通过 "requests" 发出 http 请求。这会每 10 秒阻止一次传入请求。如何实现非阻塞?

假设您使用 lua-resty-requests 库。

在计时器上下文中,lua-resty-requests 使用非阻塞 cosocket API,因此它不应该阻塞。