<div dir="ltr">Hi,<div><br></div><div>I am working on a custom module where I need to use a third party library and make sync/async calls to APIs. I do not have control over what the library does internally but any async API call on library would call a callback which indicates that content generation phase continue with forming response and sending it back to client.</div><div><br></div><div>Here is psuedo code:</div><div>- content_handler_called</div><div>   -- some_initializations</div><div>   -- Call library Async API with callback </div><div>   -- nginx should continue processing other events</div><div>   ...</div><div>   -- some point of time the callback is triggered, which should resume the request say by raising a custom event in nginx event loop so nginx can process remaining part of request.</div><div><br></div><div>As i understand nginx works primarily on events based on sockets but in this case invocation of this library api cannot generate any socket events. </div><div><br></div><div>Question is how do I pause the current request processing so nginx can continue with other requests and when api callback is trigger, nginx should be able to resume the request processing.</div><div><br></div><div>Looking at some other modules I found</div><div>1> mysql module intercepts the socket calls of libmysqlclient</div><div>2> we can use additional socket to communicate between API callback and nginx event loop. </div><div>3> I believe openresty lua module should be achieving similar async behavior for content handler phase.</div><div><br></div><div>1 is not possible, 2 is a bit bad due to additional sockets. Anyone can throw some light how openresty lua module achieves this?</div><div><br></div><div>We want to avoid upstream server model if this is already possible with nginx.</div><div><br></div><div>Is there some mechanism to trigger custom events. </div><div>Is the nginx event loop thread safe if we have some mechanism to trigger custom events?</div><div><br></div><div>Hoping for inputs. Thanks in advance!!</div><div>Kaustubh</div></div>