Hello!
On Sat, Dec 5, 2015 at 7:55 AM, Thijs Schreijer wrote:
> It's the standrad way of doing this with Lua, but is this a sensible
> approach with OpenResty?
>
You are free to use whatever you see fit. Just please keep in mind
that abstractions like coroutines come with a price. For the best
performance, try your best to avoid unnecessary coroutine API calls on
hot code paths. Having said that, I'm not entirely sure that I do
understand what exactly you are trying to achieve.
> when starting this module from `init_by_lua` can I resume it from other
> directives?
Not really. `init_by_lua` runs in the nginx master process while other
directives run in the nginx workers.
> considering this directive, will I be dragging along globals in the upvalues
> and have performance penalties when using them?
Yes. So better declare your upvalues as locals in the outer scope.
> how resilient is this from the 'yield across c boundary' error?
>
It depends on the Lua function calls on the calling chain. Some
builtin Lua functions like require() are currently implemented as C
functions and may result in such errors. Try your best to avoid them.
Regards,
-agentzh