Op 5 dec. 2015 03:09 schreef "Yichun Zhang (agentzh)" <age...@gmail.com>:
>
> 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
>
Thanks for the elaborate answer. Despite that it probably can be done, it has too many tricky elements that linger underneath the surface and are not immediately clear to everyone. So we probably better stick with regular function calls to avoid
those.
Thijs