Hello!
On Mon, Mar 3, 2014 at 10:19 AM, Martin Felis wrote:
> Now I was wondering where exactly the magic is happening. I do know a bit
> about Lua's coroutines, especially their use in
> http://www.lua.org/pil/9.4.html.
The magic happens under the hood, automatically, everytime you call a
IO-like ngx_lua primitives, like the cosocket API,
ngx.location.capture*() API, ngx.sleep(), ngx.flush(true), and etc.
Basically, if the call finds it impossible to complete the request
immediately, then it automatically *yields* the current Lua "light
thread" (implemented upon Lua coroutines), and later *resumes* the
thread later upon the corresponding events. The user Lua code that is
able to run the nonblocking IO primitives is always run inside a
"light thread" implemented atop Lua coroutines, like the Lua code
specified by content_by_lua and access_by_lua directives.
Regards,
-agentzh